• Ubuntu20.04上安装ssmtp通过SMTP方式发送邮件


    系统中使用脚本监控内存和磁盘使用情况,需要用到smtp来发送通知邮件。mailx无法在ubuntu系统上使用,经过尝试可以安装ssmtp来使用SMTP服务向外发送邮件。

     

     

    1、安装好的Ubuntu20.04中可能已经自带了邮件系统,先删除它们

    1. sudo apt autoremove postfix
    2. sudo apt autoremove sendmail

     2、安装我们需要的ssmtp和mailutils

    sudo apt install ssmtp mailutils

    3、编辑ssmtp的配置文件:

    vim /etc/ssmtp/ssmtp.conf

    3.1非TLS

    我这里是不需要身份验证,使用默认使用25端口,配置如下:

    只更新了mailhub=你的SFTP服务器

    1. #
    2. # Config file for sSMTP sendmail
    3. #
    4. # The person who gets all mail for userids < 1000
    5. # Make this empty to disable rewriting.
    6. root=poster
    7. # The place where the mail goes. The actual machine name is required no
    8. # MX records are consulted. Commonly mailhosts are named mail.domain.com
    9. mailhub=smtp.exmail.qq.com
    10. # Where will the mail seem to come from?
    11. #rewriteDomain=
    12. # The full hostname
    13. hostname=服务名
    14. # Are users allowed to set their own From: address?
    15. # YES - Allow the user to specify their own From: address
    16. # NO - Use the system generated From: address
    17. #FromLineOverride=YES

    如果需要身份认证,需要添加如下的配置

    1. AuthUser=address@mail.com
    2. AuthPass=邮箱密码

    3.2 开启了TLS 

    如果开启了TLS发送邮件,需要修改配置:

    1. #
    2. # Config file for sSMTP sendmail
    3. #
    4. # The person who gets all mail for userids < 1000
    5. # Make this empty to disable rewriting.
    6. root=poster
    7. # The place where the mail goes. The actual machine name is required no
    8. # MX records are consulted. Commonly mailhosts are named mail.domain.com
    9. mailhub=smtpdm.aliyun.com:465
    10. # Where will the mail seem to come from?
    11. #rewriteDomain=
    12. # The full hostname
    13. hostname=服务名
    14. # Are users allowed to set their own From: address?
    15. # YES - Allow the user to specify their own From: address
    16. # NO - Use the system generated From: address
    17. #FromLineOverride=YES
    18. AuthUser=address@mail.com
    19. AuthPass=邮箱密码
    20. UseTLS=Yes
    21. AuthMethod=LOGIN

     4、发送邮件测试

    1. # 不带附件发邮件:
    2. echo "This is a email content." | mail -s "Email Title" to@mail.com
    3. # 带附件发送邮件(注意在Ubuntu下附件使用附件参数-A,与Centos中的-a不同,注意大小写):
    4. echo "This is a email content." | mail -s "Email Title" -A /path/to/test.gz to@mail.com
    5. # 要显示回复邮箱地址,加上-r参数,该邮箱可以为任意指定邮箱:
    6. echo "This is a email content." | mail -s "Email Title" -r from@mail.com to@mail.com
    7. # 指定发件人名字和发件人邮箱地址(与配置中的邮箱地址一致),避免以root@hostname的来显示发件人名字
    8. echo "This is a email content." | mail -s "Email Title" -a "From: Someone " to@mail.com

    5、问题处理和日志检查

     

    查看发送邮件的日志和记录

    tail -n 10 /var/log/mail.log

    查看错误日志

    tail -n 10 /var/log/mail.err

     

     

  • 相关阅读:
    golang设计模式——解析器模式
    JDBC学习笔记
    STM32F103xx 固件函数库-1
    SSH连接服务器经常被断开解决方法
    MySQL事务机制,事务与并发
    扩展 Calcite 中的 SQL 解析语法
    修改Tomcat的默认端口号
    在.net中通过自定义LoggerProvider将日志保存到数据库方法(以mysql为例)
    我遇到的bug(活动)
    crypto:rsarsa
  • 原文地址:https://blog.csdn.net/gmaaa123/article/details/137954791