码迷,mamicode.com
首页 > 系统相关 > 详细

在命令行上 Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件

时间:2017-02-11 16:41:58      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:sendmail   还需   vim   get   live   http   read   使用   logs   

在命令行写email from ubuntu

参考:
     http://www.habadog.com/2011/11/23/send-mail-with-msmtp-mutt-linux
     http://www.absolutelytech.com/2010/07/17/howto-configure-msmtp-to-work-with-gmail-on-linux
msmtp 是一款专门负责邮件发送的客户端软件,基于GPL发布,支持TLS/SSL、DNS模式、IPv6、服务器端认证、多用户等特性。
其主页是 msmtp.sourceforge.net:
     Msmtp is an SMTP client with a sendmail compatible interface ...
安装
     sudo apt-get install mutt msmtp

如需要对TLS/SSL的支持,还需要安装 GnuTLS 或者 OpenSSL,官方推荐 GnuTLS (https://help.ubuntu.com/community/GnuTLS):
     sudo apt-get install gnutls-bin

另外,使用 Gmail 需要安装 ca-certificates:
     sudo apt-get install ca-certificates
msmtp 有 3 中工作模式:
     Sendmail mode (default)
     Server information mode
     Remote Message Queue Starting mode
对于发送邮件来说,使用 Sendmail mode (default) 就可以了:
      In  the  default sendmail mode, msmtp reads a mail from standard input and sends it to an SMTP server for delivery.

配置 msmtp
安装完后,编辑 msmtp 配置文件 ~/.msmtprc

技术分享

    defaults
    tls on
    tls_starttls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
 
    account default
    host smtp.gmail.com
    port 587
    auth on
    user username@gmail.com
    password mypass
    from username@gmail.com
    logfile ~/msmtp.log

技术分享

把 username@gmail.com 和 mypass 替换成实际的邮箱和密码就可以了,这里密码是明文。注意,发送邮件默认是 25 端口,但是 Gmail 邮件服务商用的不是 25 端口,而是 465 或 587 端口。如果不设置端口,发送邮件会报错 "Must issue a STARTTLS command first"。logfile 如果设置的时候要注意设置访问权限,保证当前用户可写。

保存后,修改访问权限
     chmod 0600 .msmtprc
如果不这样,会报错:
     must have no more than user read/write permissions

测试发送邮件:
     msmtp XXX@example.com
输入任意字符,然后按Ctrl+D退出,查看邮件是否收到。可以查看 logfile 里面的发送日志记录。
配置 mutt
查看 msmtp 安装路径
     $ which msmtp
     /usr/bin/msmtp
编辑 mutt 配置文件 ~/.muttrc

技术分享

    set sendmail="/path/to/msmtp"
    set use_from=yes
    set realname="Your Name"
    set from=you@example.com
    set envelope_from=yes
    set editor="vim"

技术分享

后面就可以用 mutt 写邮件后通过 msmtp 发送了。

小结

对于 msmtp 的详细介绍,可以参考 http://msmtp.sourceforge.net/documentation.html 或者 man msmtp。
文档里面提供了配置示例,包括 msmtp 配合 mutt 的配置。

在命令行上 Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件

标签:sendmail   还需   vim   get   live   http   read   使用   logs   

原文地址:http://www.cnblogs.com/chjbbs/p/6389261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!