你好,游客 登录 注册 搜索
背景:
阅读新闻

Mutt+Gmail+Msmtp+Ubuntu命令行发送邮件

[日期:2012-05-22] 来源:Linux社区  作者:lalor [字体:大 中 小]

这是参考人家的,我第一次照网上的资料随便设置了一次啊就可以了,但是今天弄了好久都不行,说是无法链接服务器,浪费我好多时间。提示错误如:

msmtp: cannot connect to smtp.163.com, port 25: 连接超时(Gmail邮箱也出现类似错误)
msmtp: could not send mail (account default from /home/lalor/.msmtprc)

安装 mutt 和 msmtp:
sudo apt-get install mutt msmtp

修改配置文件
nano ~/.msmtprc
输入以下内容:

01 account default
02 host smtp.gmail.com
03 from gmailuser@gmail.com
04 tls on
05 auth on
06 port 587
07 user gmailuser@gmail.com
08 password xxxxxx
09 #logfile /var/log/msmtp.log
10 logfile ~/.msmtp.log
11 tls_certcheck off

更改文件权限,主要是防止密码泄漏
chmod 600 ~/.msmtprc

nano ~/.muttrc
输入以下内容:

1 set pop_last=yes
2 set pop_pass=xxxxxx
3 set pop_user=gmailuser@gmail.com
4 set pop_host=pops://pop.gmail.com
5 set sendmail="/usr/bin/msmtp"

更改文件权限
chmod 600 ~/.muttrc


测试

1 echo 'test mutt+msmtp'|mutt -s 'test mutt+msmtp' user@gmail.com -a attatch.file
如果你跟我一样,经常给同一个人发送邮件,推荐脚本,sendboss.sh, 里面是:
text=$1                                                                     
shift 
echo -e "林老师好\n\n\n    这封邮件来自linux终端。\n\n\n\n\nLalor\n$(date)\    n" | mutt -s $text -a $* -- boos@xmu.com 
这样发送邮件的时候,就是./sendboos.sh "邮件主题" 附件.txt 附件1.txt 附件2.txt (还可以用通配符哦) linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款