Linux配置mail实现发送邮件(以centos7.0为例)
一、关闭或卸载sendmail和postfix服务
#检查是否存在 [root@agent ~]# which sendmail /sbin/sendmail [root@agent ~]# which postfix /sbin/postfix #删除 [root@agent ~]# yum remove postfix -y #检查 [root@agent ~]# which sendmail /usr/bin/which: no sendmail in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) [root@agent ~]# which postfix /usr/bin/which: no postfix in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
二、获取自己邮箱的授权码(需要有一个授权码,用来调用自己的邮箱,用来发送信息,以163邮箱为例)
步骤一:
步骤二:
步骤三:
三、安装相应的包
#检查是否存在,如果不存在则下载 [root@agent ~]# rpm -qa | grep mailx [root@agent ~]# yum install mailx -y
四、配置文件
#创建备份 [root@agent ~]# cp /etc/mail.rc /etc/mail.rc.bak [root@agent ~]# cat /etc/mail.rc set from=lucille_chu@163.com #对方收到邮件时显示的发件人 set stmp=stmp.163.com #邮箱服务器地址 set smtp-auth-user=lucille_ye@163.com #邮箱账号 set smtp-auth-password=TGSBXXXXXXXXDC #邮箱授权码 set smtp-auth=login #stmp的认证方法 set ssl-verify=ignore #忽略认证 set nss-config-dir=/etc/maildbs #证书文件目录
五、生成证书文件
[root@agent ~]# mkdir /etc/maildbs && certutil -N -d /etc/maildbs Enter a password which will be used to encrypt your keys. The password should be at least 8 characters long, and should contain at least one non-alphabetic character. Enter new password: Re-enter password:
六、发送邮件
[root@localhost ~]# echo this is a test | mail -s "test" 3089308419@qq.com [root@localhost ~]# mail -s "test" 3089308419@qq.com < abc #这是一个文件名称,文件名称内部的内容就是邮件内容
本文来自博客园,作者:小楚同学,转载请注明原文链接:https://www.cnblogs.com/lucilleye/p/15883616.html