Google Cloud Compute Engine にて、 SendGridを使用して、メールを送信する際の設定。
https://sendgrid.kke.co.jp/docs/Integrate/Mail_Servers/postfix.html
1 2 3 4 5 6 7 8 |
$ vi /etc/postfix/main.cf 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_tls_security_level = encrypt header_size_limit = 4096000 relayhost = [smtp.sendgrid.net]:587 |
1 2 3 4 5 6 7 |
$ vi /etc/postfix/sasl_passwd [smtp.sendgrid.net]:587 yourSendGridUsername:yourSendGridPassword $ sudo chmod 600 /etc/postfix/sasl_passwd $ sudo postmap /etc/postfix/sasl_passwd $ sudo systemctl restart postfix |
no mechanism available エラーが発生した場合は、以下インストール
1 |
yum -y install cyrus-sasl-plain cyrus-sasl-md5 |
◆実際にメール送信してテスト
1 2 3 4 |
$ sendmail hoge@hoge.com Subject: test test . |
/var/log/maillogに
smtp.sendgrid.net[〇.〇.〇.〇] said: 550 Unauthenticated senders not allowed
というエラーが出て送信できないときは、
/etc/postfix/sasl_passwd の情報が合っているかを確認すること
・パスワードが合っていますか?
・port番号が合っていますか?(/etc/postfix/main.cf と /etc/postfix/sasl_passwdの ポート番号が一致しているか、上記例でいうと587番)