使用 postfix 發送的電子郵件被視為垃圾郵件,有時根本無法送達

使用 postfix 發送的電子郵件被視為垃圾郵件,有時根本無法送達

我正在嘗試在運行 Ubuntu 18.04 的 VPS 上設定使用 SMTP 發送電子郵件。我正在使用 postfix、nodemailer。

當我從[電子郵件受保護],到 Gmail 帳戶時,它會卡在 Gmail 垃圾郵件資料夾中。我的評分為 6.8www.mail-tester.com,扣除這些:

-1.274 RDNS_NONE 由沒有 rDNS 的主機傳送到內部網路 這可能表示您沒有為您的主機名稱配置 rDNS 或 rDNS 與您的傳送 IP 不符

-0.896 SPF_HELO_SOFTFAIL SPF: HELO 與 SPF 記錄不符 (軟失敗)

您的訊息未使用 DKIM 簽名

我認為我的TXT記錄是正確的:

"v=spf1 ip4:[removed-server-ip] include:_spf.mail.hostinger.com ~all"

/etc/postfix/main.cf:

# 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

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# 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

# 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 = [removed-domain-name].com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost.$mydomain, localhost.[removed-domain-name].com, [removed-domain-name].com, [removed-domain-name]$
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 = loopback-only
inet_protocols = all

policyd-spf_time_limit = 3600
smtpd_recipient_restrictions =
   permit_mynetworks,
   permit_sasl_authenticated,
   reject_unauth_destination,
   check_policy_service unix:private/policyd-spf

節點郵件程式方法:

  "use strict";
  const nodemailer = require("nodemailer");

  let transporter = nodemailer.createTransport({
    sendmail: true,
    newline: 'unix',
    path: '/usr/sbin/sendmail',
    secure: true,
  })

  let info = await transporter.sendMail({
    from: '"[removed-domain-name].com" <no-reply@[removed-domain-name].com>', // sender address
    to: req.body.to, // list of receivers
    subject: "Hello", // Subject line
    text: req.body.message, // plain text body
    html: req.body.message, // html body
  });

答案1

  1. 配置您的反向 DNS。新增將您的 IP 連結到 MX 伺服器名稱的 PTR 條目

  2. 確保 main.cf 中的 myhostname 設定為您的 MX 伺服器名稱。這可能是您的 HELO 不符的原因。

  3. 您可以將 SPF 設定為「v=spf1 a mx include:_spf.mail.hostinger.com ~all」以自動接受您的 MX 作為寄件者,但 ip 應該沒問題。

  4. 將您的網域註冊到 Google 以提高送達率:https://support.google.com/a/answer/9649569?hl=en

  5. 一定要使用 DKIM :

開放金

安裝 opendkim。

配置

編輯 /etc/opendkim.conf :

  • sv簽署和驗證傳入電子郵件的模式(您可能不需要驗證模式)
  • 檢舉地址[電子郵件受保護]
  • KeyTable、SigningTable:將金鑰連結到 DNS 項目的文件
  • InternalHosts :包含受信任主機清單的文件

建立密鑰

mkdir /etc/opendkim/keys/example.com/
cd /etc/opendkim/keys/example.com/
opendkim-genkey -s mail -d example.com
chown opendkim:opendkim mail.*

參數-s稱為選擇器,-d是域。

編輯/etc/opendkim/簽名表並新增一對域/選擇器:

*@example.com mail._domainkey.example.com.

編輯/etc/opendkim/金鑰表並添加一對選擇器/鍵:

mail._domainkey.example.com example.com:mail:/etc/opendkim/keys/example.com/mail.private

編輯/etc/opendkim/TrustedHosts並插入

*.example.com
[your local network]

域名系統

您需要將公鑰新增至 DNS 。你會找到鑰匙/etc/opendkim/keys/xxx.yy/mail.txt

建立 TXT 欄位:

mail._domainkey.example.com 10800 TXT "v=DKIM1; k=rsa; p=very_long_key"

後綴

你必須讓 postfix 了解 opendkim,讓他簽署密鑰。

在其配置中取得 opendkim 的連接方法。應該是類似的inet:8891@localhost,並將其添加為過濾器主文件

smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept

最終確定

重新啟動(最終啟用)opendkim,然後啟動 postfix。檢查 DNS 中的金鑰opendkim-testkey -d example.com -s mail -vvv

請造訪 mail-tester.com 檢查。檢查 /var/log/maillog 中每封發送的電子郵件都會新增一行DKIM-Signature field added

相關內容