gpt4 book ai didi

ubuntu - 配置 postfix 以使用外部 smtp 服务器

转载 作者:行者123 更新时间:2023-12-04 18:49:53 28 4
gpt4 key购买 nike

我正在尝试将 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

最佳答案

外部 SMTP 服务器配置

  • 转到 sendgrid 和 register简介
  • 转至 Sender Authentication并创建一个新的发件人 (Picture)
    指定一些非免费邮箱(我用的是office 365 Online 账号),这样Sender 就可以被SendGrid 验证了。
  • 查收邮箱,点击验证单个发件人 信中的按钮 (Picture)
  • 转至 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 key ):
    [smtp.sendgrid.net]:587 apikey:SG.kjaksdjkfajskdk_ASDk.lkjaoIO_Kjkoaofs3i99asfd_kkjasdof99882348IKII
    应用设置:
    sudo postmap /etc/postfix/sasl_passwd
    sudo systemctl restart postfix
    在 SendGrid 验证期间测试电子邮件发送
  • 单击下一步验证集成按钮。您将在让我们测试您的集成页面。
  • 单击验证集成按钮
  • 使用 journalctl -f 运行不同的终端窗口以查看日志命令
  • 在终端中运行命令以测试邮件发送,使用 单发-r 之后在外部 SMTP 服务器配置部分创建的参数。
     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

    关于ubuntu - 配置 postfix 以使用外部 smtp 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61850054/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com