搭建mutt+msmtp发信服务

各类命令行发信

mail/mailx 都试过,相对来讲mailx比较方便点,发送带附件带邮件也很方便,例如:html

mailx -s "The Subject" -a github.png tim@abc.com < body.txt

比较头疼带是mailx其实有不少个版本,各个表现不一致,参见
https://stackoverflow.com/que...linux

我在测试带服务器是CentOS 6.x,各类尝试后没法实现发送html格式的邮件内容,只好放弃,转向muttgit

Mutt只是个客户端

首次运行mutt的时候立刻会报错。。。github

Error sending message, child exited 127 (Exec error.).

又翻阅了各类资料,mutt只是个客户端,方便你收发邮件,须要先配置真实的发信服务,例如sendmail/msmtp等服务器

vi /etc/Muttrc.local
set sendmail="/usr/bin/msmtp"

这里有个插曲,网上大多数教程是教你是设置为 /usr/sbin/sendmail,奈何CentOS下面即便安装了sendmail,也没有sendmail这个命令,查阅了n多资料,里面也是一个很复杂的故事,因此走向另一条路工具

yum install msmtp

咱们尽可能用yum能安装的工具测试

配置

vi /etc/msmtprc 
account your@email.com
host    smtp.exmail.qq.com
from    redmine@far800.com
auth    login
user    your@email.com
password        密码
account default:        your@email.com

总算遇到一个简单的配置,配置完毕以后就能使用mutt发信了。ui

mutt  -e "set content_type=text/html" -s "html test" -a file.zip -- your@email.com < body.html

One more thing

若是你是用阿里云,默认是禁止25端口出的,要么用其余端口,要么后台申请一下解封阿里云

未解决难题

虽然mutt能发信,能发html格式的信,能发html格式带附件带信,可是怎么能够将附件里面图片插入邮件主体里面,我一直没找到办法,虽然网上说mutt1.5.23版本会自动加cid,我测试了没有成功。若是你知道怎么弄,请告诉我。
https://stackoverflow.com/a/3...命令行

2天后我仍是用了mailsend 替代上述服务

https://github.com/muquit/mai...

git clone https://github.com/muquit/mailsend.git mailsend
cd mailsend
yum install -y openssl-devel
./configure --with-openssl=/usr/
make && make install

由于能够内嵌图片

-from sender@mail.com 
-to rec@mail.com 
-smtp smtp.mail.com 
-port 25 
-auth  
-user sender@mail.com 
-pass senderPassword 
-content
-type "multipart/related"  
-mime
-type text/html  
-content
-type "multipart/related" 
-mime
-type text/html 
-disposition inline 
-enc
-type "none" 
-attach "body.mailsend.html" 
-mime
-type image/png  
-enc
-type "base64"  
-disposition inline  
-content
-id "imgs_d1"  
-cs "none"  
-attach "d1.png" 
-content
-id "imgs_d2"  
-cs "none"  
-attach "d2.png" 
-content
-id "imgs_d3"  
-cs "none"  
-attach "d3.png"
相关文章
相关标签/搜索