STUDY WHILE YOU ARE BORING


  • 首頁

  • 搜索

  • 技术

  • Tags

  • 关于我

搭建mutt+msmtp发信服务

發表於 May 27, 2019   |   作者: Tim   |   分类: 技术   |   评论

各种命令行发信

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

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

比较头疼带是mailx其实有很多个版本,各个表现不一致,参见
https://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line/48588035#48588035

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

Mutt只是个客户端

首次运行mutt的时候马上会报错。。。

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发信了。

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/32227037/2809902

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

https://github.com/muquit/mailsend

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"
mutt, smtp
How to generate UPS SHIPID or Shipment IdentifyID?
Centos 6.x 上安装php 的 zbarcode 扩展

钜添

54 文章
2 分類
1 页面
GitHub 日记技术
php apache centos macos mysql https shadowsocks mac 微信 ups svn javascript outline accesskey Chrome Extension letsencrypt ssl free certification certbo wildcard renew cloudflare pgsql 归档 binlog isset array_key_exists redmine axure
© 2021 钜添   |   文章 RSS     |  登录
由 Typecho 强力驱动
主題 - NexT
Send message encrypted and private - Msg2
Build your Under Construction Page without hosting - UnderConstruct.IO