PostfixでSendGrid のSMTPを利用してメールを送信する - Postfix

PostfixでSendGrid のSMTPを利用してメールを送信する手順について紹介します。

事前準備

SendGrid のアカウントを準備します。Microsoft Azure でのアカウント取得手順はこちらの記事を参照してください。

Postfix の設定変更

/etc/postfix/main.cf を変更します。main.cf に下記の行を追記します。

/etc/postfix/main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587


/etc/postfix/sasl_passwd ファイルを作成します。ファイルには下記を記述します。

/etc/postfix/sasl_passwd

[smtp.sendgrid.net]:587 (SendgridのID):(Sendgridのパスワード)

補足:別の書式

すべてのメールをSendgridで送信するのであれば、/etc/postfix/main.cf にSendgridのID、パスワードを記入する記述方法もあります。

/etc/postfix/main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:(SendgridのID):(Sendgridのパスワード)
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

注意:smtpd_sasl_auth_enable, smtp_sasl_auth_enable の違い

smtp_sasl_auth_enable と smtpd_sasl_auth_enable はスペルが非常に似ていますが、別の設定項目です。スペルミスや記述し忘れに注意してください。
smtpd_sasl_auth_enable = yes が記入されていることを確認すると、smtp_sasl_auth_enable = yes を記述し忘れることがあります。
著者
かつて日本を代表したスーパーエンジニア (自称)
ハードウェア、電気設備、ガーデニング関係の記事を担当。
掲載日: 2016-09-04
iPentec all rights reserverd.