步骤 1:安装 mailx 和 msmtp1yum install mailx msmtp 步骤 2:配置 msmtp编辑 msmtp 的配置文件 /etc/msmtprc 或 ~/.msmtprc,并添加以下内容: 1234567891011121314151617# QQ 邮箱的 SMTP 配置defaultstls ontls_starttls ontls_trust_file /etc/pki/tls/certs/ca-bundle.crtaccount qqhost smtp.qq.comport 587from 3311987957@qq.comauth onuser 3311987957@qq.compassword xxxxxxxxxx #替换为你在 QQ 邮箱中生成的授权码。logfile ~/.msmtp.log# 设置默认账户account default : qq 步骤 3:配置 mailx 使用 msmtp为了让 mailx 使用 msmtp 作为发送工具,你需要编辑 ~/.mailrc 文件,添加以下内容: 123set sendmail=/usr/bin/msmtp #告诉 mailx 使用 msmtp 作为发送工具set from=3311987957@qq.comset message-sendmail-extra-arguments="--read-envelope-from" 步骤 4:发送带有主题和正文的邮件1echo "This is the body of the email." | mail -s "Test Subject" 3311987957@qq.com