linux mint下使用外部SMTP(如网易yeah.net)发邮件

在mint下,sentmail和postfix的配置有比较麻烦..配置了N个小时,最终弄的头晕眼花也没弄好...

下面的方法可以让你完全摆脱这两个工具...当然,你要是想做邮件服务器的话就令当别论了...你要是只想让服务器自动发个邮件什么的,用下面的就行了。

如果之前安装了sendmail, postfix.先关闭本机的sendmail服务或者postfix服务。

service sendmail stop
service postfix stop

或者直接卸载

sudo apt-get remove sendmail mailutils postfix

然后安装mailx

sudo apt-get install heirloom-mailx

然后修改/etc/nail.rc,注意是nail.rc文件。网上有些教程写的是mail.rc文件(Centos下是 /etc/mail.rc),如果mint(或ubuntu)下修改mail.rc,就会报No such file or directory as on /usr/lib/sendmail 的错误,见:http://askubuntu.com/questions/408808/no-such-file-or-directory-as-on-usr-lib-sendmail-ubuntu

在/etc/nail.rc中添加如下内容:

 
 
  1. set from=yourname@yeah.net
  2. set smtp=smtp.yeah.net
  3. set smtp-auth-user=yourname@yeah.net
  4. set smtp-auth-password=12345678
  5. set smtp-auth=login

然后就可以通过命令来发送邮件了

 
  
  1. echo testmail | mail -s 'test' -a README.md 123456789@qq.com

将echo后的内容通过管道给mail作为邮件内容,-s 表示主题,-a表示附件。

发送多个附件:

若添加多个附件,则使用多次-a,如:

扫描二维码关注公众号,回复: 3498629 查看本文章
 
  
  1. echo testfile | mail -s 'test_attachments' -a README.md -a 123.txt -a sendmail.py 12345678@qq.com

或者先将邮件内容写到一个文件,然后通过管道或者重定向将文件内容写到mail中

 
  
  1. cat 123.txt | mail -s 'test' 12345678@qq.com
  2. 或者
  3. mail -s 'test' 12345678@qq.com <123.txt

猜你喜欢

转载自blog.csdn.net/shawpan/article/details/53968642