macos OS X:向本地主机发送邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/399252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OS X: sending mail to localhost
提问by Ronn
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.
出于测试目的,我想将邮件发送到我的 localhost 用户帐户而不是我的网络服务器。我不确定如何使用 mail.app 执行此操作。任何帮助,将不胜感激。
回答by Ryan Horrisberger
@Tautologistics
@Tautoologics
OSX does have a built-in MTA (SMTP server), to turn it on you can type:
OSX 确实有一个内置的 MTA(SMTP 服务器),打开它你可以输入:
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
示例显示从我的运行 10.6.1 的机器上运行的 SMTP 服务器
>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
回答by codelogic
If you don't specifically want to use Mail.app, you can send mail using the mail
command. Open Terminal and:
如果您不是特别想使用 Mail.app,则可以使用该mail
命令发送邮件。打开终端和:
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:
这些是反引号,而不是单引号。whoami
返回当前用户的用户名并hostname
返回本地机器的主机名。它也可以是明确的:
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).
编辑:只需阅读您的说明。Mail.app 将其数据存储在 ~/Mail 中,主要存储在 SQLite 数据库(“Envenlope Index”文件)中。感兴趣的表将是mailboxes
和messages
。电子邮件的文本存储在各自邮箱/文件夹目录中的单个文件中。如果您想访问 Mail.app 已获取的电子邮件(实时),这可能是要走的路。
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.
另一种选择是使用 mbox 格式从 Mail.app 导出您的邮件,并使用 dbr 描述的技术访问它。根据是否需要实时访问,您可能能够编写一些自动导出的脚本。
回答by dbr
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)
本地邮件不存储在 POP3/IMAP 服务器中,而是使用 UNIX'y mbox。存储在/var/mail/
的文件(文件名是用户登录)
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:
不确定 Ruby(我四处搜索,但找不到任何东西,尽管毫无疑问有一个模块),但我知道 Python 有一个maildir.mbox
模块,它将以下列方式使用:
>>> msgs = mailbox.mbox("/var/mail/dbr")
>>> for msg in msgs:
... print "Subject:", msg['subject']
...
Subject: hi
回答by iDiver
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
从本地主机发送邮件 LocalhostMail 是适用于 Mac OS X 的简单快速的解决方案,它允许您通过 Mac OS X 中包含的 Mail.app 从 PHP 应用程序(或位于本地主机上的任何其他应用程序)发送电子邮件。如果您使用 PHP,只需将新消息添加到 MySQL 数据库,我们的应用程序就会通过邮件应用程序发送它们。LocalhostMail 使用您在 Mail.app 中的邮件帐户发送这些消息,因此您的本地主机不需要单独的 SMTP 服务器。本地邮箱.com
回答by Tautologistics
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 Enableror, if you don't mind the command line, use MacPortsto install postfix:
除非您运行的是 OSX Server,否则本地不会运行 SMTP/IMAP/POP3 服务器。您可以使用Post Fix Enabler轻松启动并运行,或者,如果您不介意命令行,请使用MacPorts安装 postfix:
sudo port install postfix
回答by Ronn
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:
codelogic,谢谢,我确实知道从终端发送邮件。我认为我的问题没有经过深思熟虑。我想登录我的(本地)邮件服务器,访问邮箱,并进行一些解析。所以,我假设有一个本地运行的邮件服务器,但不确定如何访问它。我正在使用红宝石:
pop = Net::POP3.new 'macbook.local'
pop.start 'me', 'mypass'
but get a Timeout::Error: execution expired
但得到一个 Timeout::Error: execution expired