问题原文
原帖链接 · oz1cz · CC BY-SA 3.0
I have an Ubuntu server running postfix. It is not the mail server for my domain.
Whenever a cron job runs for root, the output mail is not delivered locally, instead it gets sent to [email omitted] via the main mail server. This is not what I want.
I want mail for root to either be delivered locally or forwarded to [email omitted].
I've tried modifying both ~root/.forward and /etc/aliases (and running newaliases), but nothing helps (I guess these files are only checked when postfix tries to deliver mail locally).
What can I do?
This is /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
Edit:
When sending mail to root, this goes into /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 omitted]>
Mar 7 09:39:18 linux1 postfix/qmgr[28525]: F3B9C98025E: from=<[email omitted]>, size=283, nrcpt=1 (queue active)
Mar 7 09:39:18 linux1 postfix/smtp[31558]: F3B9C98025E: to=<[email omitted]>, 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
The name "ct" is my user name. I generated the above text through this command:
echo test | mail -s test root
The content of /etc/mailname is:
mydomain.com
The contents of /etc/aliases is:
root: [email omitted]
postmaster: root
where [email omitted] is where I would like root's mail to be forwarded to.
The content of /etc/hosts actually surprises me a little:
127.0.0.1 localhost
127.0.1.1 linux1.mylinux.mydomain.com linux1
where "mylinux" is the hostname of a host operating system under which linux1 runs as a virtual machine. I'm not sure how "mylinux" got in there. (But could this really be the reason for my problem?)
已采纳解答
原帖链接 · Dom · CC BY-SA 4.0
As ususal, check your logs.
In your case, the postfix daemon thinks the mail is not for it and sends it without using /etc/aliases
First check your /etc/hosts file : it should have your machine name corresponding to 127.0.1.1, like this:
127.0.1.1 linux1.mydomain.com linux1
Check your /etc/mailname too, and it should be consistent.
Check your /etc/aliases to see if root (user) is sent to another user, and redo the newaliases command.
And it should work!
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
