CentOS8 からgmail経由でメールを送信する

という風に、検索するとpostfixの設定とcyrus-sasl cyrus-sasl-plainをインストールしましょうという記事は山のように出てくると思うので、端折ります。

ざっと書くと、

postfix設定
/etc/postfix/main.cf

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
# smtp_tls_CApath = /etc/pki/tls/certs

/etc/postfix/sasl_passwdにgmailのアカウント情報を記載

[smtp.gmail.com]:587    <gmailアカウント>@gmail.com:<パスワード>

一応権限を変更しておきます。
$ sudo chmod 600 /etc/postfix/sasl_passwd

postmapでDBに反映させる
$ sudo postmap /etc/postfix/sasl_passwd

postfix再起動
$ sudo systemctl restart postfix

でもつながらない!!!!

status=deferred (SASL authentication failed; server smtp.gmail.com[74.125.204.109] said: 534-5.7.14 ?534-5.7.14 Please log in via your web browser and then try again.?534-5.7.14 Learn more at?534 5.7.14 

そんなときは、ブラウザで通したいアカウントでgoogleにログインし、

https://accounts.google.com/DisplayUnlockCaptcha

にアクセスして、再度メールを送信してあげると、その間アクセスした接続元を受け入れてくれるみたいです。
※安全性の低いアプリのアクセスもオンにしておく必要があります。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

おすすめ