Linux shell发送邮件的两种方式

示例使用163邮箱服务
mailx方式
centos编辑mail.rc
ubuntu安装heirloom-mailx,编辑s-nail.rc文件

set from=username@163.com smtp=smtp.163.com
set smtp-auth-user=username@163.com smtp-auth-password=授权码 smtp-auth=login
# SSL方式,更安全
set nss-config-dir=/etc/pki/nssdb
set ssl-verify=ignore
set smtp=smtps://smtp.163.com:465
set from=username@163.com
set smtp-auth-user=username@163.com
set smtp-auth-password=授权码
set smtp-auth=login

发送命令

echo -e "内容" | mail -v -s "标题" username@domain.com

sendmail方式

sendmail -S "smtp.163.com" -f "username@163.com"(发) -auusername@163.com -ap授权码 username@domain.com(收) -v < mail.txt
# SSL方式
sendmail -f "username@163.com"(发) -H 'exec openssl s_client -quiet -tls1 -connect smtp.163.com:465' < mail.txt -auusername@163.com -ap授权码 username@qq.com(收)

mail.txt文件内容

From:Frost-Router <username@163.com>
To: username@domain.com
Subject:邮件内容

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注