【ubuntu 18.04】安装sendmail
1. 官网
https://www.proofpoint.com/us/products/email-protection/open-source-email-solution
2. 使用qq/163/126免费个人邮箱,申请获取授权码
3. smtp 非ssl
#!/bin/bash read -p "Please Input Your Email Provider [163/qq/126]: " provider #通过read方式获得相关变量 read -p "Please Input Your Email Account: " account read -p "Please Input Your Auth-Password: " password echo "Waiting For A Moment..." sudo apt install mailutils sendmail -y >/dev/null0 cat >>/etc/mail.rc<< EOF set from=$account@$provider.com #邮箱地址 set smtp=smtp.$provider.com #smtp服务器 set smtp-auth-user=$account #邮箱账号 set smtp-auth-password=$password #授权密码,注意是授权密码,不是在web页面上登邮箱的密码,授权密码可以在邮箱的pop3/smtp设置页面自行设置。 set smtp-auth=login EOF sudo systemctl start sendmail
测试
# echo 'test' | mail -s 'test' xxxxxx@xxx.com
4. smtp ssl配置
#!/bin/bash read -p "Please Input Your Email Provider [163/qq/126]: " provider read -p "Please Input Your Email Account: " account read -p "Please Input Your Auth-Password: " password echo "Waiting For A Moment..." sudo apt-get install mailutils sendmail -y >/dev/null mkdir -p /root/.certs/ #从这里开始,均为下载ssl证书及相关配置# echo -n | openssl s_client -connect smtp.$provider.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/$provider.crt >/dev/null certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/$provider.crt >/dev/null certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/$provider.crt >/dev/null certutil -L -d /root/.certs >/dev/null cat >>/etc/mail.rc<< EOF #以下为邮箱账户相关配置# set from=$account@$provider.com set smtp=smtps://smtp.$provider.com:465 set smtp-auth-user=$account@$provider.com set smtp-auth-password=$password set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs" EOF sudo systemctl start sendmail
测试
# echo 'test' | mail -s 'test' xxxxxx@xxx.com
参考文章:https://tecadmin.net/install-sendmail-on-ubuntu/