有时,对 sendmail 问题进行故障排除变得太困难。
以下是一些最常见的 sendmail 问题。
联系支持
如果上述任何故障排除没有帮助,请向 Oracle 记录支持案例并向支持团队提供以下数据。
- 资源管理器
运行带有选项的 explorer 命令以收集有关区域、系统日志文件和 smf 日志的数据:
# /opt/SUNWexplo/bin/explorer -w default,localzones,smfextended,syslogs
- Sendmail 配置文件
# cd /etc/mail # tar cvf /tmp/mail.tar . # compress /tmp/mail.tar
- Sendmail版本
提供 sendmail 版本、编译选项和系统标识:
# /usr/lib/sendmail -d0.4 < /dev/null
- 测试邮件
发送测试邮件命令的输出:
# /usr/bin/mailx -s "test message" -v john@example.com < /dev/null
尝试详细交付
-v 选项与 mailx 一起使用时,显示邮件传递的每个步骤。
很多时候它显示了问题所在的步骤。
# mailx -v -s "test subject" john@example.com < /dev/null
验证所有配置文件是否存在
确保所有配置文件都在sendmail 配置目录下。
特别是文件 sendmail.cf 和 submit.cf
# ls -lairt /etc/mail total 364 4721 -rw-r--r-- 1 root bin 163 Jan 22 2005 Mail.rc 89143 -r--r--r-- 1 root bin 39953 Sep 3 2009 local.cf 89137 -rw-r--r-- 1 root bin 5512 Aug 6 2010 helpfile 2335 -rw-r--r-- 1 root bin 1839 Jun 28 2011 mailx.rc 89147 -rw-r--r-- 1 root bin 5 Jun 28 2011 trusted-users 89145 -r--r--r-- 1 root bin 40559 Jun 28 2011 submit.cf 89144 -r--r--r-- 1 root bin 40118 Jun 28 2011 sendmail.cf 89146 -rw-r--r-- 1 root bin 0 Jun 28 2011 local-host-names 89142 -rw-r--r-- 1 root bin 1423 Jun 28 2011 aliases 89134 lrwxrwxrwx 1 root root 11 Dec 6 10:46 main.cf -> sendmail.cf 89135 lrwxrwxrwx 1 root root 8 Dec 6 10:46 sendmail.hf -> helpfile 89136 lrwxrwxrwx 1 root root 11 Dec 6 10:46 subsidiary.cf -> sendmail.cf 71233 drwxr-xr-x 9 root mail 512 Dec 6 10:46 cf 1875 drwxr-xr-x 3 root mail 512 Dec 6 10:59 . 91727 -rw-r----- 1 root smmsp 40960 Dec 6 10:59 aliases.db 75 drwxr-xr-x 88 root sys 4608 Jan 11 20:37 ..
Sendmail 配置文件
文件 | 说明 |
---|---|
/etc/mail/sendmail.cf | 定义 sendmail 的环境 |
/etc/mail/submit.cf | 为 MSP(邮件提交程序- Mail submission program)定义环境 |
检查 SMTP 服务器连接
Sendmail 使用端口 25 连接到 SMTP 服务器。
确保系统能够在端口 25 上 telnet 到 SMTP 服务器。
有时防火墙可能会阻止端口 25,从而导致 sendmail 失败。
Telnet 到端口 25 上的 SMTP 服务器证实了这一点,如下所示:
# telnet SMTP_server 25 Trying 192.168.2.20... telnet: Unable to connect to remote host: Connection refused
将本地消息路由到本地主机端口 25.
确保本地消息路由到本地主机端口 25.
# grep MTAHost submit.cf D{MTAHost}[127.0.0.1] # grep DS submit.cf DS
对配置文件的任何更改,都需要刷新 sendmail 服务。
验证 sendmail 进程正在运行
sendmail 故障排除的第一步应该是验证 sendmail 守护进程是否正在运行。
对于 Solaris 9 及更高版本:
# ps -ef |grep sendmail root 516 1 0 Mar 19 ? 1:16 /usr/lib/sendmail -bd-q15m smmsp 515 1 0 Mar 19 ? 0:04 /usr/lib/sendmail -Ac -q15m
# /usr/ucb/ps -auxwww | grep sendmail root 6043 0.1 0.1 1280 968 console S 18:18:03 0:00 grep sendmail root 516 0.0 0.2 8240 2648 ? S Mar 19 1:16 sendmail:accepting connections smmsp 515 0.0 0.1 8240 2216 ? S Mar 19 0:03 sendmail:Queue runner@00:15:00 for /var/spool/clientmqueue
对于 Solaris 8 及以下:
# ps -ef | grep send root 271 1 0 Mar 10 ? 0:01 /usr/lib/sendmail -bd -q15m
# /usr/ucb/ps -auxwww | grep sendmail root 271 0.0 0.3 4288 1512 ? S Mar 10 0:00 sendmail:accepting connections
Sendmail 守护进程
Solaris 9 使用 2 个队列范例,因此有 2 个 sendmail 守护进程
/usr/lib/sendmail -Ac -q15m /usr/lib/sendmail -bd -q15m
在 Solaris 8 及更低版本中,有 1 个队列和 1 个守护进程
/usr/lib/sendmail -bd -q15m
错误的权限
如果任何 sendmail 配置文件具有错误的权限,则 sendmail 守护程序将无法正常工作。
sendmail 附带了一个脚本,用于验证 /etc/mail 目录中的 sendmail 相关文件的权限。
为了能够运行脚本,请停止 sednmail 守护进程,然后运行脚本:
# /usr/lib/mail/sh/check-permissions
上面的脚本不会像用户 /var/spool/mqueue 等那样检查所有的 sendmail 文件。
为了检查所有文件的权限,请使用以下命令:
# /usr/lib/sendmail -bv -d44.5 -v john@example.com
其他应该具有适当权限的重要文件是:
# ls -ild /var/spool/mqueue 71249 drwxr-x--- 2 root bin 512 Dec 6 10:46 /var/spool/mqueue
# ls -ild /var/spool/clientmqueue/ 71248 drwxrwx--- 2 smmsp smmsp 512 Dec 6 10:59 /var/spool/clientmqueue/
带有 -d44.5 开关的 sendmail 命令还会验证 mqueue 和 clientmqueue 权限。
在调试模式下发送电子邮件
为了确保sendmail可以发送邮件,我们可以使用发送邮件的调试模式。
对于此 telnet,端口 25 上的 SMTP 服务器:
# telnet onitroadmail.example.com 25 Trying 0.0.0.0... Connected to 0. Escape character is '^]'. 220 onitroadmail ESMTP Sendmail 8.14.4+Sun/8.14.4; Sun, 12 Jan 2014 15:50:48 +0530 (IST)
输入 help 列出所有可用的命令:
help 214-2.0.0 This is sendmail version 8.14.4+Sun 214-2.0.0 Topics: 214-2.0.0 HELO EHLO MAIL RCPT DATA 214-2.0.0 RSET NOOP QUIT HELP VRFY 214-2.0.0 EXPN VERB ETRN DSN STARTTLS 214-2.0.0 For more info use "HELP [topic]". 214-2.0.0 To report bugs in the implementation contact Sun Microsystems 214-2.0.0 Technical Support. 214-2.0.0 For local information send email to Postmaster at your site. 214 2.0.0 End of HELP info
按照以下命令(粗体)逐步发送电子邮件:
helo john@example.com 250 john@example.com Hello john@example.com [xx.xx.xx.xx], pleased to meet you mail from:geek@example.com 250 2.1.0 geek@example.com... Sender ok rcpt to:john@example.com 250 2.1.5 john@example.com... Recipient ok data 354 Enter mail, end with "." on a line by itself subject: This is a test message to:john@john.com Test message. End the message by "." on next line. . 250 2.0.0 m3L9aH0W018247 Message accepted for delivery quit 221 2.0.0 onitroadmail.example.com closing connection
启动 Sendmail 守护进程
如果 sendmail 守护程序未运行,请使用以下命令启动它:
对于 Solaris 9 及以下:
# /etc/init.d/sendmail start
对于 Solaris 10 及更高版本:
# svcadm enable svc:/network/smtp:sendmail # svcadm enable svc:/network/sendmail-client
检查 /var/log/syslog 审计日志文件以确认与启动 sendmail 守护进程相关的消息。
验证 sendmail.cf 中 Mailgateway 的正确输入
在 Solaris 9 及更高版本中:
# grep DS sendmail.cf DS # grep Fallback sendmail.cf O FallbackSmartHost=mailhost$?m.$m$.
在 Solaris 8 及以下版本中:
# grep DS sendmail.cf DSmailhost$?m.$m$