ubuntu 结合外部smtp发送邮件

1.安装heirloom-mail

sudo apt-get install heirloom-mailx

2.修改/etc/nail.rc文件

vim /etc/nail.rc
#在文件末尾添加
  set from=【发送的邮件地址】 set smtp=【发生的外部smtp服务器的地址】
  set smtp-auth-user=【外部smtp服务器认证的用户名】 set smtp-auth-password=【外部smtp服务器认证的用户密码】
  set smtp-auth=logi

需要注意的是“mtp-auth-password外部smtp服务器认证的用户密码”为邮箱的授权码而不是邮箱密码,授权码的位置可以在自己的邮箱设置中查看

gmail的可以使用邮箱密码,但是需要在/etc/nail.rc文件内指定端口号

set from="xxx@gamil.com"
set smtp="smtps://smtp.gmail.com:465"
set smtp-auth-user="xxx@gamil.com"
set smtp-auth-password="xxxxx"
set smtp-auth=login

 

 

3.测试


在命令行发送
echo “邮件内容” | heirloom-mailx -s “邮件标题” -a 『附件全称包括扩展名』 xxx@xxx.com

或者

mail -s 『邮件标题』-a 『邮件附件』「收件人邮箱」< 「文件」

注意:「文件」= 「邮件内容」,可以提前排版好邮件内容。比较方便。

如果不需要发送附件可以将 -a『邮件附件』去掉

成功的图片

下面是失败的截图,密码错误

 

posted @ 2018-06-05 17:28  Lyvin.zhang  阅读(1676)  评论(0编辑  收藏  举报