linux – 获取postfix以转发root的邮件

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

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

我希望root用户的邮件可以在本地发送或转发到anothermail@anotherdomain.com.

我已经尝试修改~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

编辑:

将邮件发送到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

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

回声测试| mail -s test root

/ etc / mailname的内容是:

mydomain.com

/ etc / aliases的内容是:

root: anothermail@anotherdomain.com
postmaster:    root

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

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

127.0.0.1 localhost
127.0.1.1 linux1.mylinux.mydomain.com linux1

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

解决方法

作为因果,请检查您的日志.

在您的情况下,后缀守护程序认为邮件不适用于它并在不使用/ etc / aliases的情况下发送它

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

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

检查/ etc / aliases以查看是否将root用户发送给其他人,并重做newaliases命令.

它应该工作!

相关文章

文章浏览阅读1.8k次,点赞63次,收藏54次。Linux下的目录权限...
文章浏览阅读1.6k次,点赞44次,收藏38次。关于Qt的安装、Wi...
本文介绍了使用shell脚本编写一个 Hello
文章浏览阅读1.5k次,点赞37次,收藏43次。【Linux】初识Lin...
文章浏览阅读3k次,点赞34次,收藏156次。Linux超详细笔记,...
文章浏览阅读6.8k次,点赞109次,收藏114次。【Linux】 Open...