最近又碰到一起Linux下SendMail发送邮件失败的案例,邮件发送后,邮箱收不到具体邮件, 查看日志/var/log/maillog 发现有"DSN: User unknown"以及“dsn=5.1.1, stat=User unknown”等错误信息,脱敏后的具体日志如下所示:
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnA017770: Authentication-Warning: mylnx01.xxxx.xxxx.com: oracle set sender to mylnx01-RMAN@xxxxx.com using -f
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnA017770: from=mylnx01-RMAN@esquel.com, size=17698, class=0, nrcpts=2, msgid=<201710311645.v9VGjfnA017770@mylnx01.xxxx.xxxx.com>, relay=oracle@localhost
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ2017771: <xxxxxx@esquel.com>... User unknown
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ2017771: <xxxxxx@esquel.com>... User unknown
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnA017770: to=zhangl@xxxxxx.com, ctladdr=mylnx01-RMAN@xxxxxx.com (502/502), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=77698, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnA017770: to=eeldba@xxxxxx.com, ctladdr=mylnx01-RMAN@xxxxxx.com (502/502), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=77698, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ2017771: from=<mylnx01-RMAN@xxxxxx.com>, size=17698, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnA017770: v9VGjfnB017770: DSN: User unknown
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ4017771: <mylnx01-RMAN@xxxxxx.com>... User unknown
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnB017770: to=mylnx01-RMAN@xxxxxx.com, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=48722, relay=[127.0.0.1] [127.0.0.1], dsn=5.1.1, stat=User unknown
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ4017771: from=<>, size=18722, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnB017770: v9VGjfnC017770: return to sender: User unknown
Nov 1 00:45:41 mylnx01 sendmail[17771]: v9VGjfZ6017771: from=<>, size=22066, class=0, nrcpts=1, msgid=<201710311645.v9VGjfnC017770@mylnx01.xxx.xxxxxx.com>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Nov 1 00:45:41 mylnx01 sendmail[17770]: v9VGjfnC017770: to=postmaster, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=49746, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v9VGjfZ6017771 Message accepted for delivery)
Nov 1 00:45:41 mylnx01 sendmail[17772]: v9VGjfZ6017771: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=52298, dsn=2.0.0, stat=Sent
出现这个问题的原因是因为在测试sendmail的一个功能时,在配置文件/etc/mail/local-host-names了设置了一些域名,这个配置文件可以用它来实现虚拟域名或多域名支持,一般当主机有多个名称时,而当你希望多个主机名都能收到邮件时,那么就必须设置这个配置文件。
[root@mylnx01 log]# more /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
xxxxx.com
而偏偏这台服务器的hostname跟local-host-names里面指定的不一样。从而导致邮件发送异常问题。注释掉这个主机名后,SendMail发送邮件就正常。
[root@mylnx01 log]# more /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
#xxxxx.com
参考资料:
https://www.linuxquestions.org/questions/linux-newbie-8/sendmail-error-user-unknown-dsn%3D5-1-1-a-4175460428/
http://linux.vbird.org/linux_server/0380sendmail.php#server_local-host-names