理论介绍: 1. mutt介绍: Mutt is a small but very powerful text-based mail client for Unix operating systems. 简单来说,mutt是一个MUA(邮件用户代理),类似foxmail和outlook,是不负责发送接收邮件的。 2.msmtp介绍: Msmtp is an SMTP client. In the default mode, it transmits a mail to an SMTP server (for example at a free mail provider) which takes care of further delivery.
To use this program with your mail user agent (MUA), create a configuration file with your mail account(s) and tell your MUA to call msmtp instead of /usr/sbin/sendmail. 只翻译第二部分【为了通过MUA来使用这个程序,应当使用你的账户创建一个配置文件,并告诉MUA程序调用它,而不是使用默认的sendmail】 实践操作: 一、msmtp设置 安装:apt-get install msmtp 配置文件位置:/etc/msmtprc 配置文件msmtprc defaults
tls on #这三行都是开始邮件的tls认证的
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account default
host smtp.exmail.qq.com #smtp服务器地址和端口
port 587
auth plain #使用明文方式的授权信息
user #“你的邮箱账户”
password #“密码”
from #“发件人信息[和账户名一样]
timeout 10 #设置网络超时
logfile /tmp/msmtp.log #日志
二、mutt设置 安装:apt-get install mutt
配置文件位置:/etc/Muttrc 配置文件:Muttrc set sendmail="/usr/bin/msmtp" #使用msmtp发送邮件
set use_from=yes #设置邮件包含from的header信息
set realname="honey" #设置发送邮件的用户名[账号的别名/昵称]
set editor="vim" #使用vim启动mutt交互模式
set from=my@mail.com#设置邮件from信息[use_from必须设置]
set envelope_from=yes
set copy=no #是否保留消息副本
三、mutt命令行使用
范例:
echo "详情见附件"|mutt -a /root/a.txt -s "每日订单统计" -c c@qq.com \
-- a@163.com, b@gamil.com
解释:
echo内容为邮件正文内容
-a 添加的附件
-s 邮件主题
-c 抄送的邮件人
“--”之后的内容为收件人【此处由于换行所以添加双横杠】
|