Postfixで送信されたメールはスパムとして扱われ、まったく配信されないこともあります

Postfixで送信されたメールはスパムとして扱われ、まったく配信されないこともあります

Ubuntu 18.04 を実行している VPS で SMTP を使用して電子メールを送信するように設定しようとしています。postfix、nodemailer を使用しています。

私が[メールアドレス]、Gmailアカウントに送ると、Gmailの迷惑メールフォルダに引っかかってしまいます。私は6.8点を獲得しました。メールテスター、以下の控除が適用されます:

-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

nodemailer メソッド:

  "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=ja

  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

編集信頼済みホスト挿入する

*.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、フィルターとして追加します。メイン.cf:

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で、送信されたメールごとに1行追加されていることを確認してください。DKIM-Signature field added

関連情報