LoginSignup
1
1

More than 5 years have passed since last update.

sendmailで送信元ドメインのCNAME変換を抑止する

Posted at

はじめに

Webサービスを提供するドメインのサーバからメールを送信する際、送信元のドメイン名をWebサービスのものと同じものを利用したいという状況がある。例えばsitename.comのサイトからnoreply@sitename.comでメールを送信したいという感じだ。なおこのときsitename.comにはメールサーバは存在せずよってMXレコードも存在しない。

この際sitename.comがCNAMEだった場合、sendmailはCNAMEを本来の名前に変換してからメールを転送する。この仕様はRFCで決められているようだが(ソース未確認)、sendmailではこの変換を抑止する設定が行える。抑止の設定を以下に記載する。

設定方法

バージョン確認

今回の設定はv8.7以上のsendmailで有効。

# cat /etc/issue
Amazon Linux AMI release 2017.03
Kernel \r on an \m

# /usr/sbin/sendmail -d0.101
Version 8.14.4

設定ファイルの更新

# vim /etc/mail/sendmail.mc
以下の設定を追加
define(`confDONT_EXPAND_CNAMES',`True')dnl

設定ファイルの更新(自動書き換え)

sendmailの設定ファイルのsendmail.cfはsendmail再起動時にsendmail.mcの設定に基づき上書きされる為、事前にバックアップする。

# cp -p /etc/mail/sendmail.cf{,_bak}

# service sendmail restart
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Package sendmail-cf is required to update configuration.   [WARNING]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]

cfファイルを更新する為のパッケージが必要のようなのでインストール。

# yum list | grep sendmail
https://sensu.global.ssl.fastly.net/yum/latest/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.

sendmail.x86_64                       8.14.4-9.14.amzn1             @amzn-main
sendmail-cf.x86_64                    8.14.4-9.14.amzn1             amzn-main
sendmail-devel.x86_64                 8.14.4-9.14.amzn1             amzn-main
sendmail-doc.noarch                   8.14.4-9.14.amzn1             amzn-main
sendmail-milter.i686                  8.14.4-9.14.amzn1             amzn-main
sendmail-milter.x86_64                8.14.4-9.14.amzn1             amzn-main
# yum install sendmail-cf
…
Installed:
  sendmail-cf.x86_64 0:8.14.4-9.14.amzn1

Complete!

sendmailを再起動し、設定ファイルの書き換えを確認。

# service sendmail restart
Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]

# diff /etc/mail/sendmail.cf{,_bak}
19,22d18
< ##### built by root@ip-10-0-0-160 on Tue Jul 25 12:13:01 JST 2017
< ##### in /etc/mail
< ##### using /usr/share/sendmail-cf/ as configuration include directory
< #####
442c438
< O DontExpandCnames=True
---
> #O DontExpandCnames=False

おわりに

上記の設定でCNAMEのドメインをそのまま送信元のドメインとして利用できた。
ただしこの設定は推奨されているものではなさそうなので、本来どうあるべきかは別と調査が必要。
gmailでこのサーバよりメールを受け取ると、「本当にsitename.comから送信されたものか確認できませんでした」という怪しげなメッセージが表示されるのも気になるところ。(スパムとは判断されていないが)

参考

RFC関連

バージョン確認

sendmail関連

http://www.postfix-jp.info/origdocs/cf-compat.html
http://etutorials.org/Server+Administration/Sendmail/Part+III+The+Configuration+File/Chapter+24.+The+O+Options+Configuration+Command/DontExpandCnames/
https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-email-mta-sendmail.html
http://jlug.ml.users.narkive.com/hPYHESjp/sendmail
http://network.station.ez-net.jp/server/mail/sendmail/relay.asp

postfix関連

1
1
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
1
1