0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

自宅サーバーの独自ドメイン Gmail宛のメール送信者のガイドラインに対応する

Last updated at Posted at 2024-05-31

自宅サーバーで独自ドメインを運用しています。2024年2月1日以降、自ドメイン内のユーザからGmail宛にメール送信しましたが認証エラーでメール送信ができなくなりました。元々自宅サーバーのドメインユーザーからGmail宛にメールすることは滅多になかったのでひとまず様子見をしていましたが。

今回対応することにしたのは、自宅サーバーのOSであるCentOS Stream 8 のサポート期間(EOL)が 2024年05月で切れるため、Ubuntu Server 24.04 に移行したことがきっかけです。

Googleの公式サイト

公式サイト以外の参考サイト

実際のSPFレコードの設定方法

自宅サーバーの環境

  • OS: Ubuntu Server 24.04 LTS
    Ubuntu 24.04 LTS (GNU/Linux 6.8.0-31-generic x86_64)
    ※2024年05月27日 CentOS Stream 8 (Desktop) から移行

  • DNSサーバー (権威サーバー): BIND9
    BIND 9.18.24-0ubuntu5-Ubuntu (Extended Support Version)

    • 自宅サーバーがプライマリDNSサーバー
    • プロバイダーのセカンダリーDNSサービスを利用
  • メールサーバー: Postfix 3.8.6

  • POPサーバー: Dovecot 2.3.21

  • グローバルIPアドレス: 8個

  • 自宅サーバーPC
    DNSサーバー、メールサーバー、POPサーバーを1台で運用

1. 自宅サーバーのメールアドレスから送信する場合

以降、送信側と受信側の情報を以下のような架空の値と仮定します

  • 送信側
    • ドメイン名: exampledomain.com
    • 固定IPアドレス: 111.222.333.441
    • メールサーバー: mail.exampledomain.com
    • ユーザー名: myhomeuser
  • 受信側
1-1. DNSサーバーがSPF未対応の場合

自宅サーバーのユーザのメールアドレスからGmailアドレス宛にメール送信する

/var/log/mail.log
2024-05-29T11:13:25.590353+09:00 localhost postfix/smtpd[41884]: connect from unknown[192.168.x.y]
2024-05-29T11:13:25.805661+09:00 localhost postfix/smtpd[41884]: C49BB603AFD: client=unknown[192.168.x.y], sasl_method=PLAIN, sasl_username=myhomeuser
2024-05-29T11:13:25.812643+09:00 localhost postfix/cleanup[42205]: C49BB603AFD: message-id=<e565279c-09e5-4fab-9eda-5fe309d56384@exampledomain.com>
2024-05-29T11:13:25.843911+09:00 localhost postfix/qmgr[41875]: C49BB603AFD: from=<myhomeuser@exampledomain.com>, size=627, nrcpt=1 (queue active)

次に認証エラーが出力された箇所を以下に示します※改行を入れています

2024-05-29T11:13:27.659502+09:00 localhost postfix/smtp[42206]: C49BB603AFD:
 to=<example.user1@gmail.com>, 
 relay=gmail-smtp-in.l.google.com[64.233.189.27]:25,
 delay=1.8, delays=0.05/0.02/0.73/1, dsn=5.7.26, 
 status=bounced (host gmail-smtp-in.l.google.com[64.233.189.27] said:
    550-5.7.26 Your email has been blocked because the sender is
    unauthenticated. 550-5.7.26 Gmail requires all senders to authenticate with
    either SPF or DKIM. 550-5.7.26  550-5.7.26  Authentication results:
    550-5.7.26  DKIM = did not pass 550-5.7.26  SPF [exampledomain.com] with ip:
    [111.222.333.441] = did not pass 550-5.7.26  550-5.7.26  For instructions on
    setting up authentication, go to 550 5.7.26
    https://support.google.com/mail/answer/81126#authentication
    98e67ed59e1d1-2c1a779ad32si1087902a91.127 - gsmtp (in reply to end of DATA
    command)

この後 [Undelivered Mail Returned to Sender] メールがユーザに届きます。

This is the mail system at host mail.exampledomain.com.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system

<example.user1@gmail.com>: host gmail-smtp-in.l.google.com[64.233.189.27] said:
    550-5.7.26 Your email has been blocked because the sender is
    unauthenticated. 550-5.7.26 Gmail requires all senders to authenticate with
    either SPF or DKIM. 550-5.7.26  550-5.7.26  Authentication results:
    550-5.7.26  DKIM = did not pass 550-5.7.26  SPF [exampledomain.com] with ip:
    [111.222.333.441] = did not pass 550-5.7.26  550-5.7.26  For instructions on
    setting up authentication, go to 550 5.7.26
    https://support.google.com/mail/answer/81126#authentication
    98e67ed59e1d1-2c1a779ad32si1087902a91.127 - gsmtp (in reply to end of DATA
    command)

Reporting-MTA: dns; mail.exampledomain.com
X-Postfix-Queue-ID: A491C603B58
X-Postfix-Sender: rfc822; myhomeuser@exampledomain.com
Arrival-Date: Thu, 30 May 2024 15:52:18 +0900 (JST)

Final-Recipient: rfc822; example.user1@gmail.com
Original-Recipient: rfc822;example.user1@gmail.com
Action: failed
Status: 5.7.26
Remote-MTA: dns; gmail-smtp-in.l.google.com
...以下省略...
1-2. 正引きゾーンファイルにSPF対応レコードを追加する

(1) 正引きゾーンファイルの変更

【最低限必要な設定例】IPv4のみ

[TXTレコードの内容]
"v=spf1 +a:mail.exampledomain.com +mx +ip4:111.222.333.441 -all"

exampledomain.com.  IN  TXT "v=spf1 +a:mail.exampledomain.com +mx +ip4:111.222.333.19 -all"

※1 忘れずにシリアル番号もカウントアップします。2024052705 ;Serial
※2 DNSサーバーをリロード

(2) ゾーンファイル更新後のドメインの確認

※ドメイン更新まで数分待ちます

$ dig txt exampledomain.com

; <<>> DiG 9.18.18-0ubuntu0.22.04.2-Ubuntu <<>> txt exampledomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3069
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;exampledomain.com.		IN	TXT

;; ANSWER SECTION:
exampledomain.com.	979	IN	TXT	"v=spf1 +a:mail.exampledomain.com +mx +ip4:111.222.333.441 -all"

;; Query time: 24 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Wed May 29 15:40:04 JST 2024
;; MSG SIZE  rcvd: 118

(3) 対応後に再度メールを送信

今度は認証エラーなく送信に成功しました。

/var/log/mail.log
2024-05-29T15:43:42.062135+09:00 localhost postfix/smtpd[44726]: connect from unknown[192.168.x.y]
2024-05-29T15:43:42.248526+09:00 localhost postfix/smtpd[44726]: 3C95A6033B5: client=unknown[192.168.x.y], sasl_method=PLAIN, sasl_username=myhomeuser
2024-05-29T15:43:42.358656+09:00 localhost postfix/cleanup[45430]: 3C95A6033B5: message-id=<cddeae0d-d0c1-434c-968e-c693d34cf744@exampledomain.com>
2024-05-29T15:43:42.390509+09:00 localhost postfix/qmgr[41875]: 3C95A6033B5: from=<myhomeuser@exampledomain.com>, size=670, nrcpt=1 (queue active)
2024-05-29T15:43:44.219605+09:00 localhost postfix/smtp[45431]: 3C95A6033B5: to=<example.user1@gmail.com>, relay=gmail-smtp-in.l.google.com[64.233.189.27]:25, delay=2, delays=0.15/0.02/0.63/1.2, dsn=2.0.0, status=sent (250 2.0.0 OK  1716965024 d9443c01a7336-1f44c971ca8si93938005ad.326 - gsmtp)
2024-05-29T15:43:44.220497+09:00 localhost postfix/qmgr[41875]: 3C95A6033B5: removed

メーラーのGmailアドレスにメッセージが届していることを確認します

From  myhomeuser <myhomeuser@exampledomain.com>
To    example.user1@gamil.com
Subject SPFレコード追加の件

SPFレコードをDNS正引きゾーンファイルに追加しました。

最後に

2024年05月31日 現在 私の環境ではDNSサーバーの正引きゾーンファイルに SPF対応レコードを追加するだけでGmail宛にメールを送信することができました。しかしGmailスパム対策が2024年06月01日に全面適用されることにより、SPF対応だけで問題ないかどうか注視していかなければならないようです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?