Postfix mydestination 问题

Postfix mydestination 问题

更新:我通过将 myorigin 设置为 $myhostname(“prime.example.com”)解决了这个问题。现在系统邮件发送到“[电子邮件保护]“,这正是我想要的。我的应用程序明确表示它想要从“[电子邮件保护]“,而且这也有效。我不完全确定这是做事的正确方法,因此我仍然愿意接受进一步的建议。

我希望本地生成的邮件(当前通过 smtp 发送)改为在本地投递。目前,它们发送到 user@domain 而不是 user@hostname。我在 Ubuntu Server 14.04 上使用 Postfix 2.11。

域名:example.com

主机名:prime.example.com

在 /etc/hosts 中:

127.0.1.1 prime.example.com prime
127.0.0.1 localhost

/etc/postfix/main.cf 摘录:

myhostname = prime.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname ("example.com")
mydestination = prime.example.com, localhost.example.com localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 127.0.0.1
inet_protocols = all

example.com 的 MX 记录指向其他地方;该服务器用于发送电子邮件,而不是接收。

我可以在本地发送电子邮件(显示来自:[电子邮件保护])通过命令行:

echo "This is the body of the email" | mail -s "This is the subject line" root

我还可以通过 smtp 为该域发送电子邮件(显示来自:[电子邮件保护]) 来自 cli:

echo "This is the body of the email" | mail -s "This is the subject line" -a "From: [email protected]" <to-address>

然而,当一个简单的 cron 作业运行时,邮件会通过 smtp 发送到[电子邮件保护],不是本地[电子邮件保护]正如我想要的那样。

我以为mydestination应该阻止向非本地发送邮件,所以要么是我弄错了,要么是某个地方的配置有问题。任何提示都将不胜感激。

答案1

如果您希望所有发往 example.com 的邮件都在本地处理,则应将 example.com 添加到 mydestination。否则,服务器会查找 example.com 的 MX 记录,并相应地通过 smtp 发送邮件。

如果您希望程序将本地通知发送到 prime.example.com,则应该更改 /etc/mailname 以满足您的 mydestination,如 man mailname 中所述:

描述

   The  file /etc/mailname is a plain ASCII configuration file, which on a
   Debian system contains the visible mail name of the system.  It is used
   by many different programs, usually programs that wish to send or relay
   mail, and need to know the name of the system.

相关内容