用ubuntu命令行发送邮件

转载自:http://blog.csdn.net/psh2009/article/details/9280713


试了挺多方法,这个果然就好用,感激. 以下为转载。

文章主要是参考http://www.cnblogs.com/276815076/archive/2011/10/11/2207214.html

验证发送成功,请大胆尝试,但后果自负哈大笑

不用说首先安装软件,ubuntu大家都知道的哈,傻瓜式sudo apt-get install mutt msmtp,一切默认设置就行。

接着开始各种配置,很简单,不想麻烦,可以copy,当然我也是ctrl+c的

MUTT
系统全局设置/etc/Muttrc,如果使用某个系统用户,可以在~/.muttrc中设置。

vi .muttrc
set sendmail="/usr/bin/msmtp"
set use_from=yes
set realname="FengYuBin"
set 
[email protected]
set envelope_from=yes

MSMTP
创建~/.msmtprc和~/.msmtp.log,分别为配置和日志文件。
vi .msmtprc

account default
host smtp.163.com
from [email protected]
auth plain
user  fyb
password 123456
logfile ~/.msmtp.log
由于password是明码,所以我们需要修改此文件的权限。
chmod 600 .msmtprc
touch ~/.msmtp.log
查看SMTP服务器是否支持认证的TLS加密:

敲入如下命令:msmtp --host=smtp.163.com --serverinfo回车

SMTP server at smtp.163.com (m5-86.163.com [202.108.5.86]), port 25:
    163.com Anti-spam GT for Coremail System (163com[20050206])
Capabilities:
    PIPELINING:
        Support for command grouping for faster transmission
    AUTH:
        Supported authentication methods:
        PLAIN LOGIN

到这里,你可以使用mutt来发送邮件了,我们测试一下。

echo "test" |mutt -s "my_first_test" ***@gmail.com

去邮箱看看是否成功!

最后, 如果要把文件内容追加到邮件里,可以用mutt -s "my_first_test" ***@gmail.com < test.txt

如果是要以附件形式添加,因为暂时不需要,请百度。


猜你喜欢

转载自blog.csdn.net/bingyu880101/article/details/52957180