Linux 下使用sendmail搭建邮件服务器

时间:2021-03-12 17:52:19

 

1、准备email环境

一般采用yum安装足够用了,安装命令:

#安装sendmail和配置工具sendmail-cf           

yum install mailx -y

yum -y install sendmail

yum install -y sendmail-cf

 

#SMTP认证服务

yum install -y saslauthd

 

安装完后,mail的日志位置一般是:/var/log/maillog 

 

测试,有2种方法:

(1)      命令行测试:echo "This is test mail" | mail -s 'Test mail aboutsomething else.' Mchdba@sohu.com

(2)      文件测试:mail -s "test" 1621861384@qq.com < /home/email_content.txt

 

日志调试参考:

调整日志级别(详细程度):修改配置文件define(confLOG_LEVEL',16’)dnl 默认为9 ,或者调用命令时指定sendmail-O LogLevel=14,详细参考:http://www.ibm.com/support/knowledgecenter/zh/ssw_aix_71/com.ibm.aix.networkcomm/sendmail_debugflags.htm

 

 

 

2、报错信息:My unqualified host name (ht_121_90) unknown

 

这种错误报的比较多,看后台日志,基本信息如下:

Oct  9 14:04:02 localhost sendmail[7902]: restarting /usr/sbin/sendmail due to signal

Oct  9 14:04:02 localhost sm-msp-queue[7899]: restarting /usr/sbin/sendmail due to signal

Oct  9 14:04:03 localhost sm-msp-queue[8089]: starting daemon (8.14.4): queueing@01:00:00

Oct  9 14:04:03 localhost sendmail[8091]: starting daemon (8.14.4): SMTP+queueing@01:00:00

Oct  9 14:04:13 localhost sendmail[8123]: starting daemon (8.14.4): SMTP+queueing@01:00:00

Oct  9 14:04:13 localhost sm-msp-queue[8131]: starting daemon (8.14.4): queueing@01:00:00

Oct  9 14:04:48 localhost sendmail[8200]: My unqualified host name (ht_121_90) unknown; sleeping for retry

 

分析:

系统sendmail时会把以ht_121_90作为域名加到主机名后组成完整的长名ht_121_90. ht_121_90来访问,系统当然就会报“unable to qualify my own domain name (ht_121_90)”

 

解决方法:

1)在vim /etc/mail/sendmail.cf 配置文件中查找 Dj$w,并在此行下面增加这一行。

 Dj$w.

 

2)在/etc/hosts 增加一行

[root@ht_121_90 ~]# more /etc/hosts

127.0.0.1 ht_121_90 ht_121_90.  #注意后面有一个点.

192.168.121.90 tracker.powerlong.com

[root@ht_121_90 ~]#

 

然后重启sendmail服务

[root@ht_121_90 ~]# service sendmailrestart

Shutting down sm-client:                                   [  OK  ]

Shutting down sendmail:                                    [  OK  ]

Starting sendmail:                                         [  OK  ]

Starting sm-client:                                        [  OK  ]

[root@ht_121_90 ~]#

 

再试发送email到qq邮箱,是OK,成功了

 [root@ht_121_90~]# mail -s "test" 1621861384@qq.com </home/zhanghaoxiang/data-integration/log/job_dw_main.log

You have new mail in /var/spool/mail/root

[root@ht_121_90 ~]#

 

查看后台也会显示发送成功了:

Oct 9 14:14:03 localhost sendmail[8345]: u996E3pw008345:to=1621861384@qq.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00,mailer=relay, pri=48078, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent(u996E36P008346 Message accepted for delivery)

Oct 9 14:14:04 localhost sendmail[8348]: STARTTLS=client, relay=mx3.qq.com.,version=TLSv1/SSLv3, verify=FAIL, cipher=RC4-SHA, bits=128/128

Oct 9 14:14:07 localhost sendmail[8348]: u996E36P008346:to=<1621861384@qq.com>, ctladdr=<root@ht_121_90> (0/0), delay=00:00:04,xdelay=00:00:04, mailer=esmtp, pri=138302, relay=mx3.qq.com. [183.57.48.35],dsn=2.0.0, stat=Sent (Ok: queued as )

^C

 

 

 

 

3、再报错误DSN: Service unavailable

发送邮件到139邮箱,后台日志报错如下:

Oct  9 14:11:13 localhost sendmail[8330]: u996BDDX008328: to=<mchdba@139.com>, ctladdr=<root@ht_121_90> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120436, relay=mx1.mail.139.com. [221.176.66.188], dsn=5.0.0, stat=Service unavailable

Oct  9 14:11:13 localhost sendmail[8330]: u996BDDX008328: u996BDDX008330: DSN: Service unavailable

Oct  9 14:11:13 localhost sendmail[8330]: u996BDDX008330: to=<root@ht_121_90>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31646, dsn=2.0.0, stat=Sent

 

解决:

这种一般是网络问题,网络不能访问139的邮件服务器导致,找网络工程师协调查看下服务器的网络配置。

 


参考文章:

http://blog.csdn.net/enemyisgodlike/article/details/50723866

http://zdm2008.blog.163.com/blog/static/2049154520139795219380/