tags:

views:

681

answers:

6

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.

+2  A: 

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" [email protected]

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.

codelogic
A: 

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

Ronn
Ah ok, I updated my answer after reading your clarification.
codelogic
+2  A: 

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
Tautologistics
+1  A: 

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 [email protected]  Tue Dec 30 13:43:57 2008
Return-Path: <[email protected]>
X-Original-To: dbr
Delivered-To: [email protected]
Received: by parabola.local (Postfix, from userid 501)
        id 4FEA1158E36; Tue, 30 Dec 2008 13:43:57 +1030 (CST)
To: [email protected]
Subject: hi
Message-Id: <[email protected]>
Date: Tue, 30 Dec 2008 13:43:57 +1030 (CST)
From: [email protected] (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
dbr
+1  A: 

@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
serpico7456
A: 

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

iDiver