Mac OS X 下用命令行发送邮件

msmtp 是个 smtp 客户端。如果只是用命令行发送邮件,并不需要能接受邮件,用它正好。用 Sendmail、Postfix 的话,就有些杀鸡用牛刀的感觉,而且它们配置起来真很让人痛苦。

安装 msmtp

$ brew install msmtp # 如果没有 brew,请去 http://brew.sh/ 安装下

配置

~/.mailrc

<!-- lang: shell -->
set sendmail=/usr/local/bin/msmtp

~/.msmtprc

<!-- lang: shell -->
# Use an external SMTP server with insecure authentication.
# (manually choose an insecure authentication method.)
# Note that the password contains blanks.

defaults

####################################################################
# A sample configuration using Gmail
####################################################################

# account name is "gmail".
# You can select this account by using "-a gmail" in your command line.
account gmail
host smtp.gmail.com
tls on
tls_certcheck off
port 587
auth login
from yourname@gmail.com
user yourname
password yourpassword

# If you don't use any "-a" parameter in your command line,
# the default account "gmail" will be used.
account default: gmail

~/.msmtprc 需要设置正确的访问权限

<!-- lang: shell -->
$ chmod 600 ~/.msmtprc

试用

<!-- lang: shell -->
$ echo "Hello world" | mail -s "msmtp test at `date`" yourfriend®@gmail.com

还想说的

上面的 ~/.msmtprc 使用明文存放密码、非加密方式验证,虽方便但不安全。想要更安全,可参看 Dropping sendmail-postfix for msmtp

如果想在 Linux、Windows 上做同样的事情,可参看How to send emails with msmtp on Windows or Linux or Mac OS X

文章还参考了

How to send an email from command line?

MSMPTQuickStart

Archlinux msmtp

转载于:https://my.oschina.net/uhziel/blog/186683

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值