获取后缀来转发根邮件

我有一个运行Postfix的Ubuntu服务器。 这不是我的域的邮件服务器。

每当cron作业为root运行时,输出邮件不会在本地传递,而是通过主邮件服务器发送到[email protected]。 这不是我想要的。

我希望根邮件可以在本地交付或转发到[email protected]

我已经尝试修改~root/.forward/etc/aliases (并运行newaliases),但没有任何帮助(我猜这些文件只在postfix试图在本地传递邮件时被检查)。

我能做什么?

这是/etc/postfix/main.cf

 smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no append_dot_mydomain = no readme_directory = no smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache myhostname = linux1.mydomain.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = linux1.mydomain.com, localhost.linux1.mydomain.com, localhost relayhost = my.isps.relayhost.com mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only 

编辑:

当发送邮件到根目录,这进入/var/log/mail.log

 Mar 7 09:39:17 linux1 postfix/pickup[31381]: F3B9C98025E: uid=1000 from=<ct> Mar 7 09:39:18 linux1 postfix/cleanup[31556]: F3B9C98025E: message-id=<[email protected]> Mar 7 09:39:18 linux1 postfix/qmgr[28525]: F3B9C98025E: from=<[email protected]>, size=283, nrcpt=1 (queue active) Mar 7 09:39:18 linux1 postfix/smtp[31558]: F3B9C98025E: to=<[email protected]>, orig_to=<root>, relay=my.isps.relayhost.com[<IP address omitted>]:25, delay=0.72, delays=0.19/0.02/0.27/0.25, dsn=2.0.0, status=sent (250 Ok: queued as A97F5D8126) Mar 7 09:39:18 linux1 postfix/qmgr[28525]: F3B9C98025E: removed 

名称“ct”是我的用户名。 我通过这个命令生成了上面的文本:

echo test | mail -s test root

/etc/mailname的内容是:

 mydomain.com 

/etc/aliases的内容是:

 root: [email protected] postmaster: root 

其中[email protected]是我希望根邮件被转发到的地方。

/etc/hosts的内容实际上让我感到惊讶:

 127.0.0.1 localhost 127.0.1.1 linux1.mylinux.mydomain.com linux1 

其中“mylinux”是linux1作为虚拟机运行的主机操作系统的主机名。 我不确定“mylinux”是如何进入的。 (但这真的可以成为我的问题的原因?)

作为ususal,检查你的日志。

在你的情况下,postfix守护进程认为邮件不适合它,并发送它,而不使用/etc/aliases

首先检查你的/etc/hosts文件:它应该有你的机器名称对应于127.0.1.1 linux1.mydomain.com linux1

检查你的/etc/mailname ,它应该是一致的。

检查/etc/aliases以查看root用户是否被发送给其他人,然后重新执行newaliases命令。

它应该工作!

如果mydestination为空或不包含$myhostname那么/etc/aliases将被忽略,因为postfix认为电子邮件不是本地传递,因此不会应用本地别名。 所以,把mydestination放在默认值( postconf -d mydestination或者从main.cf删除它),并且日志应该显示to=<...>作为别名地址。

在某些情况下(即将所有邮件转发到外部系统),只需将root的crontab中的MAILTOvariables设置为真实的电子邮件地址就更简单了。 这应该几乎绕过传统的传递到根,只是让它到你想要的地方。

 # Root's crontab [email protected] 0 0 * * * /usr/bin/somescript