sendmail简单配置

yum -y install sendmail sendmail-cf
service sendmail start
service saslauthd status
if [ $? -ne 0 ];then
service saslauthd start
fi

#配置Senmail的SMTP认证
将下面两行内容前面的dnl去掉。在sendmail文件中,dnl表示该行为注释行,是无效的,因此通过去除行首的dnl字符串可以开启相应的设置行。
vim /etc/mail/sendmail.mc
....
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl


#设置Sendmail服务的网络访问权限(如果是直接本机调用,则不用操作,采用默认的127.0.0.1。不过最后还是改成0.0.0.0)
将127.0.0.1改为0.0.0.0,意思是任何主机都可以访问Sendmail服务。
如果仅让某一个网段能够访问到Sendmail服务,将127.0.0.1改为形如192.168.1.0/24的一个特定网段地址。
....(和上一个设置在同一个文件里)
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl


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


启动服务(如果发现sendmail dead but subsys locked,那就执行"service postfix status"查看postfix是否默认开启了,如果开启的话,就关闭postfix,然后再启动或重启sendmail服务即可。)
service sendmail start
service saslauthd restart
chkconfig sendmail on && chkconfig saslauthd on


测试发送邮箱
第一种方式:安装sendmail即可使用。
yum -y install mailx
echo 'This is test mail'> 1.txt
mail -s 'Test mail' zhang****[email protected] < 1.txt

释:This is test mail是主题内容,Test mail是邮件标题


如果是发送给多个邮件,就使用-c参数:
echo "This is test mail" | mail -s 'test' -c [email protected] [email protected]

tail -f /var/log/maillog


第二种方式:利用外部的smpt服务器
上面第一种方式中,/bin/mail命令会默认使用本地sendmail发送邮件,这样要求本地的机器必须安装和启动Sendmail服务,配置非常麻烦,而且会带来不必要的资源占用。
而通过修改配置文件可以使用外部SMTP服务器,可以达到不使用sendmail而用外部的smtp服务器发送邮件的目的。

修改/etc/mail.rc文件(有的版本叫/etc/nail.rc,添加下面内容:
set [email protected] smtp=smtp.domain.comset smtp-auth-user=username smtp-auth-password=passwordset smtp-auth=login

参数说明:
from是发送的邮件地址
smtp是发生的外部smtp服务器的地址
smtp-auth-user是外部smtp服务器认证的用户名。注意一定要填写邮件全称!!
smtp-auth-password是外部smtp服务器认证的用户密码
smtp-auth是邮件认证的方式

配置完成后,就可以正常发送邮件了,如下
[root@slave-node ~]# vim /etc/mail.rc //在文件底部添加
set [email protected] smtp=smtp.huanqiu.cn [email protected] smtp-auth-password=zh@123bj smtp-auth=login

现在开始发邮件:
[root@slave-node ~]# echo "hello world" |mail -s 'test666' [email protected]


VIA:https://www.cnblogs.com/kevingrace/p/6143977.html

猜你喜欢

转载自www.cnblogs.com/smlile-you-me/p/10356857.html