Linux命令行发送邮件是什么?

我先从整体上来解释下 Linux 中邮件命令怎么把邮件传递给收件人的。邮件命令撰写邮件并发送给一个本地邮件传输代理(MTA,如 sendmail、Postfix)。邮件服务器和远程邮件服务器之间通信以实际发送和接收邮件。下面的流程可以看得更详细。

linux脚本可以发送邮件吗?

创建脚本文件

mkdir /root/bin

cd /root/bin

vim sendmail.sh

yum -y install mailx

yum install -y sendmail

yum install -y sendmail-cf

yum -y install bc

echo "TRUST_AUTH_MECH('EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl" >> /etc/mail/sendmail.mc

echo "define('confAUTH_MECHANISMS', 'EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl" >> /etc/mail/sendmail.mc

sed -i s#127.0.0.1#0.0.0.0#g /etc/mail/sendmail.mc

grep "OPTIONS" /etc/mail/sendmail.mc

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

echo 'setfrom=xxx@qq.com'>> /etc/mail.rc #发送邮件管理邮箱

echo 'set smtp=smtp.exmail.qq.com' >> /etc/mail.rc#邮件服务器设置

echo 'setsmtp-auth-user=xxx@qq.com'>> /etc/mail.rc #发送邮件邮箱,一般和管理邮箱相同

echo 'set smtp-auth-password=passwd' >> /etc/mail.rc#发送邮件邮箱的密码

echo 'set smtp-auth=login' >> /etc/mail.rc

IP=$(ifconfig|grep '10.100'|awk '{print $2}') #获取服务器IP

abc="abc.mail.com"

echo "$IP `hostname` $abc" >> /etc/hosts

systemctl enable sendmail

systemctl start sendmail

systemctl status sendmail

退出

推荐内容