`
qdzheng
  • 浏览: 66860 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

在命令行下发送邮件(mailx+msmtp)

阅读更多

有时候Linux管理员需要在命令行发送邮件到指定的邮箱。但是,又不愿在机器上装一个全功能的mail服务器(如PostFix、SendMail之类),在这种情况下,msmtp是个不错选择。

一、安装
   pacman -S mailx msmtp
二、msmtp的配置/etc/msmtprc,以gmail的smtp服务器为例:

host smtp.gmail.com
domain gmail.com
tls on
tls_starttls on
tls_certcheck off
protocol smtp


auth on
user yourname@gmail.com
password yourpassword
from yourname@gmail.com


需要将yourname、yourpassword改成实际的用户名及密码。
三、mailx的配置
默认情况下,mailx使用/usr/sbin/sendmail来发送邮件,这个程序包括在sendmail、postfix中。可以编辑~.mailrc配置文件来更改这个配置(做个/usr/bin/msmtp到/usr/sbin/sendmail的符号链接也可):

set sendmail="/usr/bin/msmtp"


四、测试
echo 'test from msmtp' | mail -s 'hello' demo@163.com

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics