步骤 1: 安装 mailutils
对于基于 Debian 的系统(如 Ubuntu)
sudo apt-get install mailutils
对于基于 Red Hat 的系统(如 CentOS/RHEL)
sudo yum install mailx
步骤 2: 创建配置文件
sudo vi /etc/mail.rc
set from=your-email@qq.com
set smtp=smtp.qq.com:587
set smtp-use-starttls
set smtp-auth=login
set smtp-auth-user=your-email@qq.com
set smtp-auth-password=your-authorization-code
步骤 3: 测试发送邮件
echo "This is a test email sent using mailx." | mailx -s "Test Email" your-recipient@example.com
Q&A
报错:Error in certificate: Peer’s certificate issuer is not recognized.
解决方法:
步骤 1: 运行以下命令生成一个证书
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
步骤 2: 更新nss-config-dir配置
echo "set nss-config-dir=/root/.certs" | sudo tee -a /etc/mail.rc