CentOS7(postfix)でSMTPにmailgunを使う方法

提供: Wikiducca
2020年1月10日 (金) 11:01時点におけるYosuke (ノート | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

概要

サーバ自身からではなく外部の SMTP サーバ(mailgun)を用いてメールを送信する環境を構築する。

手順

必要なパッケージをインストール

# yum install postfix cyrus-sasl-plain cyrus-sasl-md5 mailx

main.cf 編集

# cp -p /etc/postfix/main.cf /etc/postfix/main.cf.org
# vi /etc/postfix/main.cf

以下を末尾に追記。

### mailgun settings.
relayhost = smtp.mailgun.org
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = AUTH LOGIN

sasl_passwd 作成・読み込み

# MY_DOMAIN="example.jp"
# MAILGUN_CREDENTIALS="012345abc1a234d567890b12345abc0-123a1b45-c1234567"
# echo 'smtp.mailgun.org postmaster@${MY_DOMAIN}:${MAILGUN_CREDENTIALS}' > /etc/postfix/sasl_passwd
# chmod 600 /etc/postfix/sasl_passwd
# postmap /etc/postfix/sasl_passwd
# systemctl restart postfix

以上で、mail コマンド等で mailgun 経由でメールを送信できるようになった。

参考・引用

https://blog.birkhoff.me/send-email-thru-mailgun-on-centos-7/