CentOS下邮件服务sendmail的安装及简单配置

sendmail是Linux下优秀的邮件系统。在不做任何设定的情况下,sendmail发出邮件的邮箱源地址形如userid@localhost.localdo,这种地址几乎会被所有的邮箱认定为SPAM(垃圾邮件)或直接拒收。

1、 Sendmail安装

在CentOS下,sendmail一般默认是随操作系统一起安装的。如果安装系统时没有安装sendmail服务,手动安装sendmail也很简单:


# yum install -y sendmail 
# yum install -y sendmail-cf

2、 Senmail的SMTP认证配置(不需要认证的可忽略此步)

首先确认saslauthd服务是否安装或启动。

安装saslauthd服务:
# yum install -y saslauthd


启动saslauthd服务:
# service saslauthd start


(1) 配置Senmail的SMTP认证

# vi /etc/mail/sendmail.mc


dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 
dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

将上面两行的dnl去掉。在sendmail文件中,dnl表示该行为注释行,是无效的,因此通过去除行首的dnl字符串可以开启相应的设置行。

(2) 设置Sendmail服务的网络访问权限

# vi /etc/mail/sendmail.mc


DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl 

将127.0.0.1改为0.0.0.0,意思是任何主机都可以访问Sendmail服务。如果仅让某一个网段能够访问到Sendmail服务,将127.0.0.1改为形如192.168.1.0/24的一个特定网段地址。

3、 生成Sendmail配置文件

Sendmail的配置文件由m4来生成,m4工具在sendmail-cf包中。如果系统无法识别m4命令,说明sendmail-cf软件包没有安装。

生成Sendmail的配置文件:


m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf  

需要重启Sendmail才能使配置文件生效。

4、postfix与sendmail的冲突问题
在Linux服务器(CentOS release 6.6)上配置好了sendmail后,测试发送邮件时发现有问题,检查sendmail服务的状态,发现其处于“sendmail dead but subsys locked”, 检查发现postfix服务也在运行。只需要将postfix服务停掉即可。为什么会出现这种情况呢?Something was occasionally causing the postfix service to start which then caused the status of sendmail to jump to dead but subsys locked. 两种似乎不兼容。
 
操作步骤:
 
(1):检查sendmail服务的状态

[root@DB-Server ~]# service sendmail statussendmail dead but subsys lockedsm-client (pid  22112) is running...

(2):检查postfix服务的状态


[root@DB-Server ~]# service postfix statusmaster (pid  1777) is running...

 
(3):停止postfix服务

[root@DB-Server ~]# service postfix stopShutting down postfix: [  OK  ]

 
 
(4):重新启动sendmail服务

[root@DB-Server ~]# service sendmail stopShutting down sm-client: [  OK  ]Shutting down sendmail: [FAILED][root@DB-Server ~]# service sendmail stop[root@DB-Server ~]# service sendmail startStarting sendmail: [  OK  ]Starting sm-client: [  OK  ]


(5):禁用postfix在reboot后自动启动

      检查一下是否有设定 postfix 在 reboot 后自动启动

chkconfig --list | grep postfix

chkconfig postfix off