目次

PostfixからGmailへのリレー設定

PostfixからGmailへのメールリレー設定のメモ

Googleのアプリパスワードの取得

Googleアカウントの管理画面からアプリパスワードを作成し取得します。

パスワードDBの作成

アプリパスワードをSASLパスワードDBに設定します。

gmail
[smtp.gmail.com]:587 username@gmail.com:sqirskhmgkcbvujw

※パスワードは仮のものです。

パスワード設定ファイルを作成します。

 $ sudo postmap /etc/postfix/gmail
 $ ls -ltr /etc/postfix

gmail.dbが生成されたパスワードファイルです。

SASLモジュールの導入

libsasl2-modulesを導入します。

$ apt install libsasl2-modules

Postfix設定

/etc/postfix/main.cfにSASL設定などを追加します。

main.cf
myhostname = mail.domain1.jp
mydomain = domain1.jp
 
relayhost = [smtp.gmail.com]:587
 
# Gmail relay
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain
smtp_sasl_password_maps = hash:/etc/postfix/gmail
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_tls_security_level = encrypt
smtp_use_tls = yes