我已经使用 postfix 和 dovecot 在 mail.example.com 服务器上设置了 smtp 服务器,该服务器在端口 25 上运行。然后我还使用邮寄(http://mailin.io) 在 mail.example.com 服务器上,但在端口 10025 上运行。
此邮件的目的只是解析从 postfix 收到的传入电子邮件,并通过 webhook 将解析的结果作为 json 发布。
由于 postfix 没有 api 来解析电子邮件内容,所以我使用 mailin。
在我的/etc/postfix/main.cf我添加了这一行:
relay_domains = localhost:10025 ## this is the mailin smtp server running on port 10025
这是我的邮件日志:
[root@mailserver ~]# tail -f /var/log/maillog
Dec 17 04:36:07 mailserver postfix/smtpd[6858]: connect from localhost[127.0.0.1]
Dec 17 04:36:07 mailserver postfix/smtpd[6858]: 6E2C21848: client=localhost[127.0.0.1]
Dec 17 04:36:07 mailserver postfix/cleanup[6868]: 6E2C21848: message-id=<[email protected]>
Dec 17 04:36:07 mailserver postfix/qmgr[6386]: 6E2C21848: from=<[email protected]>, size=506, nrcpt=1 (queue active)
Dec 17 04:36:07 mailserver postfix/smtpd[6858]: disconnect from localhost[127.0.0.1]
Dec 17 04:36:07 mailserver dovecot: lda([email protected]): msgid=<[email protected]>: saved mail to INBOX
Dec 17 04:36:07 mailserver postfix/pipe[6871]: 6E2C21848: to=<[email protected]>, relay=dovecot, delay=0.09, delays=0.06/0.01/0/0.02, dsn=2.0.0, status=sent (delivered via dovecot service)
Dec 17 04:36:07 mailserver postfix/qmgr[6386]: 6E2C21848: removed
正如我注意到的,电子邮件已成功发送,但邮件功能不起作用。
我的问题是,由于只有 Postfix 会接收电子邮件,因此 mailin 如何接收/解析传入的电子邮件?
有人可以解释一下如何正确地做到这一点吗?
更新 [2014/12/17]: postconf -n 命令的输出
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailbox_command = /usr/lib/dovecot/deliver
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = localhost
mynetworks_style = host
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
recipient_delimiter = +
relay_domains = mysql:/etc/postfix/mysql_relay_domains.cf
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_mailbox_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport = dovecot
virtual_gid_maps = static:5000
virtual_uid_maps = static:5000
答案1
免责声明:我假设你仅有的想要解析电子邮件邮寄并且电子邮件将不会再次投递至 dovecot。
为此,请替换 virtual_transport 参数,使其变为
virtual_transport = smtp:[127.0.0.1]:10025
就是这样,postfix 不会将邮件发送到 dovecot,而是通过 SMTP 端口 10025 将邮件传递给 mailin。
[更新]
根据此邮件日志
Dec 18 mailserver postfix/smtpd[13147]: connect from mailserver.cebufreelancer.com[9.40.80.111]
Dec 18 mailserver postfix/smtpd[13147]: 61C252F1F: client=mailserver.cebufreelancer.com[9.40.80.111]
Dec 18 mailserver postfix/cleanup[13157]: 61C252F1F: message-id=<[email protected]>
Dec 18 mailserver postfix/qmgr[13139]: 61C252F1F: from=<[email protected]>, size=523, nrcpt=1 (queue active)
Dec 18 mailserver postfix/smtpd[13147]: disconnect from mailserver.cebufreelancer.com[9.40.80.111]
Dec 18 mailserver postfix/smtp[13160]: 61C252F1F: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10025, delay=0.14, delays=0.05/0.04/0/0.04, dsn=4.1.8, status=deferred (host 127.0.0.1[127.0.0.1] said: 450 4.1.8 <[email protected]>: Recipient address rejected: Domain not found (in reply to RCPT TO command))
Postfix 成功将邮件发送到 mailin。该错误
Recipient address rejected: Domain not found
来自 mailin(实际上来自 simplesmtp,一个 SMTP 库)。查看代码在 github。
Mailin 在接收电子邮件时会尝试解析收件人域。当我尝试cebufreelancer.com
从我的 VM 解析域时,结果为 NXDOMAIN。这就是 mailin 报告错误的原因。