• Linux系统发邮件


    Linux系统发送邮件

    管理服务器时我们经常需要写一些监测脚本,然后在出问题的时候通过邮件来通知

    SMTP

    SMTP(Simple Mail Transfer Protocol)简易邮件传输通讯协议

    SMTP服务器是遵循SMTP协议的发送邮件服务器,用来发送或中转你发出的电子邮件。可以理解为就是用来寄信的,而且大多数SMTP服务器也是免费的。

    QQ邮箱的SMTP

     

    授权码作为密码

    mailx

    yum install -y mailx

    系统指定SMTP服务器

    vim /etc/mail.rc

    在文件最后插入:

    set from=345678910@qq.com
    set smtp=smtp.qq.com  
    set smtp-auth-user=345678910
    set smtp-auth-password=授权码
    set smtp-auth=login  

    from是你设置stmp服务的邮箱地址,也就是用来发送邮件的邮箱地址
    smtp是发生的外部smtp服务器的地址,如qq的smtp.qq.com
    smtp-auth-user是外部smtp服务器认证的用户名
    smtp-auth-password是外部smtp服务器认证的用户密码(授权码)
    smtp-auth是邮件认证的方式

    发送邮件测试

    echo ‘test’ | mail -s 'test' 345678910@qq.com

    mail命令语法

    mail  -s  "标题"  邮件地址  < 文件

    mail  -s  "test" 345678910@qq.com </etc/hosts

    echo  "正文" | mail  -s  "test"  345678910@qq.com

    使用465端口发送邮件

    阿里云回复:

      由于国际与国内均对垃圾邮件进行严格管控,我国《互联网信息服务管理办法》、《中国互联网协会反垃圾邮件规范》均对垃圾邮件进行说明与管理规范。 鉴于服务器25端口被大量垃圾邮件充斥,严重影响广大用户正常使用。为了共同维护良好的网络环境,自即日起阿里云新购服务器不再提供25端口邮件服务, 建议您尝试使用465加密端口发送邮件。

    创建证书:

    mkdir /root/.certs
    echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/.certs/163.crt
    certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/163.crt
    certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/163.crt
    certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs/./ -i /root/.certs/163.crt
    certutil -L -d /root/.certs

    mail.rc:

    set from=345678910@163.com
    set smtp=smtps://smtp.163.com:465
    set smtp-auth-user=345678910
    set smtp-auth-password=password
    set smtp-auth=login
    set ssl-verify=ignore
    set nss-config-dir=/root/.certs
  • 相关阅读:
    CodeForces 1059B
    CodeForces 714A
    浅析母函数
    CodeForces 816C 思维
    CodeForces 816B 前缀和
    CodeForces
    Java项目读取resources资源文件路径那点事
    原型模式
    一次给女朋友转账引发我对分布式事务的思考
    连续最大字段和问题
  • 原文地址:https://www.cnblogs.com/lcword/p/15704420.html
Copyright © 2020-2023  润新知