refs:
http://www.cnblogs.com/xiazh/archive/2011/04/15/2016966.html
http://huangrs.blog.51cto.com/2677571/788379
http://www.wilf.cn/post/centos-mutt-msmtp-setup.html
http://www.cnblogs.com/xiazh/archive/2011/04/15/2016966.html
http://huangrs.blog.51cto.com/2677571/788379
http://www.wilf.cn/post/centos-mutt-msmtp-setup.html
sudo apt-get install msmtp
sudo apt-get install mutt
sudo apt-get install mutt
安装好了这两个包之后,就是进行相关配置文件的配置了:
1)msmtp是个命令行的邮件客户端
配置msmtp
创建 ~/.msmtprc 和 ~/.msmtp.log,分别为配置文件和日志文件
vi .msmtprc
account default
host smtp.corpease.net
from zhenghongxia@anjuke.com
auth plain
user zhenghongxia@anjuke.com
password xxxxxxx
logfile ~/.msmtp.log
做完了以上的配置之后,可以进行邮件的发送测试了:
/usr/local/msmtp/bin/msmtp yourReceiveremail@test.com
输入任意字符,然后按Ctrl+D退出,查看邮件是否收到。
由于设置了日志,可以到 /usr/local/msmtp/msmtp.log,查看日志,发信成功失败都会有记录。
查看SMTP服务器是否支持认证的TLS加密:
1
zhxia
@
zhxia
-
Desktop:~
$
msmtp
--
host
=
smtp.corpease.net
--
serverinfo
2 SMTP server at smtp.corpease.net (mail3.corpease.net [ 61.145 . 121.45 ]), port 25 :
3 corpease.net Anti - spam GT for Coremail System (corpease[ 20100527 ])
4 Capabilities:
5 PIPELINING:
6 Support for command grouping for faster transmission
7 AUTH:
8 Supported authentication methods:
9 PLAIN LOGIN
2 SMTP server at smtp.corpease.net (mail3.corpease.net [ 61.145 . 121.45 ]), port 25 :
3 corpease.net Anti - spam GT for Coremail System (corpease[ 20100527 ])
4 Capabilities:
5 PIPELINING:
6 Support for command grouping for faster transmission
7 AUTH:
8 Supported authentication methods:
9 PLAIN LOGIN
2)配置 mutt,系统全局设置配置文件在 /etc/muttrc,如果使用某个系统用户,可以在~/.muttc中设置,没有该文件,就自己创建。
vi .muttrc
1
set sendmail
=
"
/usr/bin/msmtp
"
2 set use_from = yes
3 set realname = " zhxia "
4 set from = zhenghongxia @ anjuke.com
5 set envelope_from = yes
2 set use_from = yes
3 set realname = " zhxia "
4 set from = zhenghongxia @ anjuke.com
5 set envelope_from = yes
发送邮件测试:
1
echo
"
hello world
"
|
mutt
-
s
"
title
"
252578390
@
qq.com
一般情况下,均可已正常接收邮件。
下面是一个比较完整的发送邮件示例:
1
echo
"
hello
"
|
mutt
-
s
"
title
"
252578390
@
qq.com,zhenghong
-
xia
@
163
.com
-
c
402714871
@
qq.com
-
a
/
tmp
/
ip.tmp
发送给多人,抄送,添加附件
address
=
"
zhenghongxia@anjuke.com
"
echo $content | mutt - s " ${subject} " - e 'set content_type = " text/html " ' - e 'send - hook . " my_hdr X-Priority: 1 " ' $address
echo $content | mutt - s " ${subject} " - e 'set content_type = " text/html " ' - e 'send - hook . " my_hdr X-Priority: 1 " ' $address
发送邮件时设置邮件的文本类型为:html格式,邮件的等级为:重要