• Linux 下使用网易的SMTP服务器 发送邮件


    最近在研究服务器高可用集群 (HA)……

    尝试配置keepalived,

    却发现其全局配置(global_defs )中发送邮件的SMTP服务器配置只有简单 smtp_server 一个选项。

    那么,如果希望使用外部邮箱(比如 163邮箱)或需要用户名密码认证的邮箱发送提醒邮件该如何配置?

    以“keepalived smtp auth”为关键词 Google之 …… 

    看到keepalived作者对这个问题的看法:I dont see urgent matter for thi……

    不过issues中也给出了解决方案 :

    Install a MTA like Postfix and securely relay any message to the company's SMTP server. 

    遂,经过 “精挑细选”……决定用 Postfix 搭一个MTA,作为网易邮箱的代理,最终实现使用keepalived中自带邮件通知机制进行通知提醒。

    Postfix 是一种电子邮件服务器,它是由任职于IBM华生研究中心(T.J. Watson Research Center)的荷兰籍研究员Wietse Venema为了改良sendmail邮件服务器而产生的。最早在1990年代晚期出现,是一个开放源代码的软件。

    以下才是是重点:


    测试环境:CentOS-6.8-x86_64-minimal

    安装Postfix :

    > yum install postfix mail cyrus-sasl-* -y 

    配置Postfix

    > vi  /etc/postfix/main.cf

    (Postfix主要配置文件,再其末尾添加以下配置)

    #指定默认的邮件发送服务器
    relayhost = [smtp.163.com]:25
    #激活sasl认证
    smtp_sasl_auth_enable = yes
    #指定sasl密码配置文件
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    #非匿名登录
    smtp_sasl_security_options = noanonymous
    #指定认证类型 (提示:需要yum安装cyrus-sasl-*组件,否则发邮件时会报错:no mechanism available)
    smtp_sasl_type = cyrus
    #linux用户与发件人的对应关系配置文件
    sender_canonical_maps = hash:/etc/postfix/sender_canonical  
     
    

    > vi /etc/postfix/sasl_passwd

    (邮箱账号和密码文件,每行一个。 创建好后需要使用postmap命令使配置文件生效)

    [smtp.163.com]:25   guang384@163.com:my163Password

    > postmap /etc/postfix/sasl_passwd

    > vi /etc/postfix/sender_canonical

    (linux用户和发件人对应关系,每行一个)

    root   guang384@163.com

    > postmap /etc/postfix/sender_canonical

    重启Postfix

    > service postfix restart

    尝试发送邮件

    >echo "hello world"  |mail -s  test guang384@qq.com

    (可以用 mailq 命令查看发送队列,清空mailq队列 : postsuper -d ALL  )

  • 相关阅读:
    stax(和dom4j功能一样,这个是基于流的一种处理方式)
    JAXB(xml和对象的转换)
    wsdl理解
    webservice心得
    ZT 分智网博客 – 职场、面试技巧、职业规划
    discern concern fifth sixth
    ZT I Believe I Can Fly(我相信我能飞)
    ZT 理解class.forName()
    ZT 第9章 Framework的启动过程
    android 智能指针的学习先看邓凡平的书扫盲 再看前面两片博客提升
  • 原文地址:https://www.cnblogs.com/tugeler/p/6620150.html
Copyright © 2020-2023  润新知