获取 postfix 来转发 root 的邮件

oz1*_*1cz 15 email linux ubuntu postfix

我有一台运行 postfix 的 Ubuntu 服务器。它不是我的域的邮件服务器。

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

我希望 root 的邮件要么在本地发送,要么转发到 anothermail@anotherdomain.com。

我已经尝试修改~root/.forward/etc/aliases(并运行新别名),但没有任何帮助(我猜这些文件只在 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
Run Code Online (Sandbox Code Playgroud)

编辑:

当向 root 发送邮件时,这会变成/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=<20130307083917.F3B9C98025E@linux1.mydomain.com>
Mar  7 09:39:18 linux1 postfix/qmgr[28525]: F3B9C98025E: from=<ct@mydomain.com>, size=283, nrcpt=1 (queue active)
Mar  7 09:39:18 linux1 postfix/smtp[31558]: F3B9C98025E: to=<root@mydomain.com>, 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
Run Code Online (Sandbox Code Playgroud)

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

echo test | mail -s test root

内容/etc/mailname为:

mydomain.com
Run Code Online (Sandbox Code Playgroud)

内容/etc/aliases为:

root: anothermail@anotherdomain.com
postmaster:    root
Run Code Online (Sandbox Code Playgroud)

anothermail@anotherdomain.com 是我希望将 root 的邮件转发到的地方。

内容/etc/hosts其实有点让我吃惊:

127.0.0.1 localhost
127.0.1.1 linux1.mylinux.mydomain.com linux1
Run Code Online (Sandbox Code Playgroud)

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

Dom*_*Dom 15

像往常一样,检查您的日志。

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

首先检查你的/etc/hosts文件:它应该有你对应的机器名127.0.1.1,像这样:

127.0.1.1  linux1.mydomain.com  linux1
Run Code Online (Sandbox Code Playgroud)

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

检查您的/etc/aliasesroot(用户)是否已发送给另一个用户,然后重做该newaliases命令。

它应该工作!


Col*_*inM 8

如果mydestination为空或不包含$myhostname/etc/aliases则将被忽略,因为 postfix 认为电子邮件不是本地交付,因此不会应用本地别名。因此,保留mydestination默认值(postconf -d mydestination或将其从 中删除main.cf),日志应将 显示to=<...>为您的别名地址。