【问题标题】:Configure postfix to use external smtp server配置 postfix 以使用外部 smtp 服务器
【发布时间】:2020-09-03 02:21:23
【问题描述】:

我正在尝试将 postfix 配置为使用外部 smtp 服务器。我已设法将其配置为从 root@host-name 发送电子邮件,但我希望能够从我的域发送它。我关注了this tutorial,还添加了smtp_generic_maps,但它不起作用。
这是我的配置:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_security_level=may
smtpd_tls_protocols = !SSLv2, !SSLv3
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = aba-elearning.com
#ABA.Moodle
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
milter_protocol = 2
milter_default_action = accept
smtpd_milters = inet:localhost:12301
non_smtpd_milters = inet:localhost:12301




# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

smtp_generic_maps = hash:/etc/postfix/generic

【问题讨论】:

    标签: ubuntu postfix-mta


    【解决方案1】:

    外部 SMTP 服务器配置

    1. 转到 sendgrid 和 register 个人资料
    2. 转到Sender Authentication 并创建一个新发件人 (Picture)
      指定一些非免费邮箱(我使用的是 office 365 Online 帐号),以便 SendGrid 验证发件人。
    3. 检查您的邮箱并点击信中的验证单一发件人按钮 (Picture)
    4. 转到SMTP Relay integration page并创建一个apikey,您将放入postfix的sasl_passwd文件(Picture)。在您将其插入并验证之前,请勿关闭验证页面。

    后缀配置:

    安装一些包和configure postfix:

    sudo apt install postfix mailutils
    

    接下来配置/etc/postfix/main.cf文件,添加或修改下一行:

    smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
    biff = no
    append_dot_mydomain = no
    compatibility_level = 2
    smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
    smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
    smtpd_tls_security_level=may
    
    smtp_tls_CApath=/etc/ssl/certs
    smtp_tls_security_level=encrypt
    smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
    
    smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
    myhostname = localhost.localdomain
    
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = test
    mydestination = $myhostname, localhost
    relayhost = [smtp.sendgrid.net]:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_tls_security_options = noanonymous
    

    创建/etc/postfix/sasl_passwd文件(进一步获取api秘钥):

    [smtp.sendgrid.net]:587 apikey:SG.kjaksdjkfajskdk_ASDk.lkjaoIO_Kjkoaofs3i99asfd_kkjasdof99882348IKII
    

    应用设置:

    sudo postmap /etc/postfix/sasl_passwd
    sudo systemctl restart postfix
    

    在 SendGrid 验证期间测试电子邮件发送

    1. 单击下一步验证集成按钮。您将进入让我们测试您的集成页面。

    2. 单击验证集成按钮

    3. 使用journalctl -f 命令运行不同的终端窗口以查看日志

    4. 在终端中运行命令以测试邮件发送,使用 外部 SMTP 服务器配置部分中创建的 -r 参数后的 Single Sender

       echo "Test Email message body" | mail -r xxxx@yyyy.onmicrosoft.com -s "Email test subject" zzzz@gmail.com
      

    结果,我的 gmail.com 邮箱收到了一封测试信。我也将它发送到我的 yahoo.com 邮件地址,并且在延迟一段时间后它也已放入垃圾邮件文件夹。最好不要在雅虎上使用这种方法,因为它不可靠。 “十年”内将不会检索重要通知。

    接下来配置/usr/local/nagios/etc/objects/commands.cfg

    define command {
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -r xxxx@yyyy.onmicrosoft.com -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
    }
    

    这里我将/usr/sbin/sendmail 替换为/usr/bin/mail -r xxxx@yyyy.onmicrosoft.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-08
      • 2013-10-26
      • 1970-01-01
      • 2018-07-21
      • 2018-07-21
      • 2017-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多