centos7 使用指定邮箱发送邮件

一、安装sendmail与mail

  1、安装sendmail:

     1) centos下可以安装命令:yum -y install sendmail

     2) 安装完后启动sendmail命令:service sendmail start

  2、安装mail

     安装命令:yum install -y mailx

二、发送邮件

    1、通过文件内容发送

     发送命令:mail -s 'mail test' abc@qq.com < mailtest.txt ("mail test"为邮件主题,abc@qq.com为收件人邮箱,mailtest.txt保存邮件内容)

        或者:echo "邮件内容" |mail -s "主题"  abc@qq.com

  2、通过管道符直接发送

     发送命令:echo "this is my test mail" | mail -s 'mail test' abc@qq.com

三、设置发件人信息

  上述发送邮件默认会使用linux当前登录用户信,通常会被当成垃圾邮件,指定发件人邮箱信息命令:vi /etc/mail.rc,编辑内容如:

set from=username@163.com
set smtp=smtp.163.com
set smtp-auth-user=username
set smtp-auth-password=yourpassword
set smtp-auth=login

注意:163邮箱需要开启一个授权密码,在非163专用客户端登陆都要使用授权密码登陆。

原文地址:https://www.cnblogs.com/benjamin77/p/8571902.html