如何使用Liunx SMTP协议发邮件
最近需要使用Liunx发送邮件,记录日常。(使用的为Cent OS的mail命令)
一、关闭本机的sendmai服务或者postfix服务
#sendmial
service sendmail stop
chkconfig sendmail off
#postfix
service postfix stop
chkconfig postfix off
#再狠一点就直接卸载吧..
yum remove sendmail
yum remove postfix
二、修改mail.rc添加发送邮件的邮箱,SMTP服务器等信息
vi /etc/mail.rc
set from=xxx@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=xxx
set smtp-auth-password='授权码'
set smtp-auth=login
获取授权码(以QQ邮箱为例)
三、正式发送邮件命令
# -s 为添加标题 -a 为添加附件
#1、使用管道符 | 发送邮件
echo hello world | mail -s " title" xxxxx@xx.com #发送正文hello world给xxxxx@xx.com
echo hello world | mail -a '附件路径' -s " title" xxxxx@xx.com #发送正文hello world 附件给xxxxx@xx.com
#、使用指向符 < 发送邮件
mail -a 'add_path' -s ‘TITLE’ xxxxx@xx.com< context.txt #发送正文context.txt,附件为add_path给xxxxx@xx.com
注意点:
使用smtp发送邮件的服务器需要打开SMTP 25 端口,目前阿里云,腾讯云等云VPS默认关闭25端口。