OS X: sending mail to localhost

前端 未结 6 783
臣服心动
臣服心动 2021-02-04 20:07

For testing purposes I want send mail to my localhost user account rather than my webserver. I am unsure how to do this using mail.app. Any help would be appreciated.

相关标签:
6条回答
  • 2021-02-04 20:38

    I'm looking to login into my (local) mail server, access a mailbox, and do some parsing. So, I assume there's a mail server running locally but not sure how to access it

    The local mail isn't stored in a POP3/IMAP server, but rather using a UNIX'y mbox. A file stored in /var/mail/ (the file-name is the users login)

    For example..

    $ mail dbr
    Subject: hi
    test
    ^d # ctrl+d (EOF)
    $ cat /var/mail/dbr 
    From dbr@parabola.local  Tue Dec 30 13:43:57 2008
    Return-Path: <dbr@parabola.local>
    X-Original-To: dbr
    Delivered-To: dbr@parabola.local
    Received: by parabola.local (Postfix, from userid 501)
            id 4FEA1158E36; Tue, 30 Dec 2008 13:43:57 +1030 (CST)
    To: dbr@parabola.local
    Subject: hi
    Message-Id: <20081230031357.4FEA1158E36@parabola.local>
    Date: Tue, 30 Dec 2008 13:43:57 +1030 (CST)
    From: dbr@parabola.local (dbr)
    
    test
    

    Not sure about Ruby (I had a search around, but couldn't find anything, although there is undoubtably a module for this), but I know Python has a maildir.mbox module, which would use in the following way:

    >>> msgs = mailbox.mbox("/var/mail/dbr")
    >>> for msg in msgs:
    ...     print "Subject:", msg['subject']
    ... 
    Subject: hi
    
    0 讨论(0)
  • 2021-02-04 20:39

    If you don't specifically want to use Mail.app, you can send mail using the mail command. Open Terminal and:

    mail -s "Testing" `whoami`@`hostname`
    <type something>
    Ctrl-D to finish and send
    

    Those are backticks, not single quotes. whoami returns the current user's username and hostname returns the local machine's hostname. It could also be explicit:

    mail -s "Testing" john@mymac.local
    

    EDIT: Just read your clarification. Mail.app stores it's data in ~/Mail, mostly in an SQLite database (the 'Envenlope Index' file). The tables of interest would be mailboxes and messages. The text of the email is stored in individual files in the respective mailbox/folder directories. This would probably be the way to go, if you want to access email that has been fetched by Mail.app (in realtime).

    Yet another option would be to export your mail from the Mail.app using the mbox format and access it using the technique described by dbr. Depending on whether or not realtime access is desired, you might be able to script something up that automates the export.

    0 讨论(0)
  • 2021-02-04 20:48

    @Tautologistics

    OSX does have a built-in MTA (SMTP server), to turn it on you can type:

    sudo launchctl start org.postfix.master   
    

    then you can send mail to localhost like you desire


    sample showing an SMTP server running from my machine running 10.6.1

    >telnet 127.0.0.1 25
    Trying 127.0.0.1...
    telnet: connect to address 127.0.0.1: Connection refused
    telnet: Unable to connect to remote host
    
    >sudo launchctl start org.postfix.master
    
    >telnet 127.0.0.1 25
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    220 machinename.example.com ESMTP Postfix
    
    0 讨论(0)
  • 2021-02-04 20:53

    codelogic, thanks, I did know about sending mail from the terminal. I think my question was not well thought out. I'm looking to login into my (local) mail server, access a mailbox, and do some parsing. So, I assume there's a mail server running locally but not sure how to access it. I'm using ruby:

    pop = Net::POP3.new 'macbook.local'
    pop.start 'me', 'mypass'
    

    but get a Timeout::Error: execution expired

    0 讨论(0)
  • 2021-02-04 20:58

    Send mail from localhost LocalhostMail is a simple and fast solution for Mac OS X that lets you send email messages from your PHP-application (or any other, located on localhost) by Mail.app included with Mac OS X. If you use PHP, just add to MySQL database new messages, and our application will send them through a Mail application. LocalhostMail uses your mail account in Mail.app to send these messages, so you do not need a separate SMTP-server for your localhost.localhostmail.com

    0 讨论(0)
  • 2021-02-04 21:00

    Unless you are running OSX Server, then there's no SMTP/IMAP/POP3 server running locally. You can get one up and running very easily using Post Fix Enabler or, if you don't mind the command line, use MacPorts to install postfix:

    sudo port install postfix
    
    0 讨论(0)
提交回复
热议问题