Postfix でSMTPリレーを設定する - Postfix

PostfixでSMTPリレーを設定する方法を紹介します。

設定のいきさつ

最近は、gmailにメールを送信する際に一般のSMTPサーバーからはメールを受け付けず、ISP事業者からの信頼されたIPアドレスからしかメールを受け付けない仕様になってしまいました。
gmailの仕様の詳細はこちら(http://support.google.com/mail/bin/answer.py?answer=10336)

gmailからのエラーメッセージ(details)

信頼されていないIPアドレスからメールを送信した場合、下記のエラーメッセージが戻ってきます。
Reporting-MTA: dns; mail.orgdomain.net
X-Postfix-Queue-ID: 16104C008E
X-Postfix-Sender: rfc822; name@orgdomain.net
Arrival-Date: Fri, 22 Nov 2013 19:16:06 +0900 (JST)

Final-Recipient: rfc822; ipentec_dummy@gmail.com
Original-Recipient: rfc822;ipentec_dummy@gmail.com
Action: failed
Status: 5.7.1
Remote-MTA: dns; gmail-smtp-in.l.google.com
Diagnostic-Code: smtp; 550-5.7.1 [nnn.nnn.nnn.nnn] The IP you're using to send
    mail is not authorized to 550-5.7.1 send email directly to our servers.
    Please use the SMTP relay at your 550-5.7.1 service provider instead. Learn
    more at 550 5.7.1 http://support.google.com/mail/bin/answer.py?answer=10336
    yf2si15324787pab.201 - gsmtp


このような状況から、ISP事業者のSMTPサーバーを経由してメールを送信する必要が出てきました。

設定方法 (ローカルメール以外をリレーする)

main.cf に relayhost を追加します。

main.cf (設定前 300行付近)

# INTERNET OR INTRANET

# The relayhost parameter specifies the default host to send mail to
# when no entry is matched in the optional transport(5) table. When
# no relayhost is given, mail is routed directly to the destination.
#
# On an intranet, specify the organizational domain name. If your
# internal DNS uses no MX records, specify the name of the intranet
# gateway host instead.
#
# In the case of SMTP, specify a domain, host, host:port, [host]:port,
# [address] or [address]:port; the form [host] turns off MX lookups.
#
# If you're connected via UUCP, see also the default_transport parameter.
#
#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]

main.cf (設定後 300行付近)

# INTERNET OR INTRANET

# The relayhost parameter specifies the default host to send mail to
# when no entry is matched in the optional transport(5) table. When
# no relayhost is given, mail is routed directly to the destination.
#
# On an intranet, specify the organizational domain name. If your
# internal DNS uses no MX records, specify the name of the intranet
# gateway host instead.
#
# In the case of SMTP, specify a domain, host, host:port, [host]:port,
# [address] or [address]:port; the form [host] turns off MX lookups.
#
# If you're connected via UUCP, see also the default_transport parameter.
#
#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
relayhost = [mmm.majorprovider.ne.jp]
行頭が"#"の行はすべてコメントアウトされている行ですので、コメントアウトなしで”relayhost” の行を加えます。
"="の後ろの"[]"で囲まれた、"mmm.majorprovider.ne.jp"の部分にリレーするSMTPサーバーのホスト名を入力します。
著者
かつて日本を代表したスーパーエンジニア (自称)
ハードウェア、電気設備、ガーデニング関係の記事を担当。
最終更新日: 2024-01-06
作成日: 2013-11-22
iPentec all rights reserverd.