NETWORK ENGINEER BLOG

Tips and Reviews for Engineers

Postfix から Gmail へリレーする設定

Gmail の設定

Gmail の設定で安全性の低いアプリを許可します。

Postfix の設定

Postfix と SASL インストール
# yum install -y postfix
# yum -y install cyrus-sasl-plain cyrus-sasl-md5
Postfix の設定
# vi /etc/postfix/main.cf
myhostname = host.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mynetworks = 127.0.0.0/8
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable  = yes
smtp_sasl_password_maps = hash:/etc/postfix/smtp-auth-passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
#tls setting
smtp_use_tls = yes
smtp_tls_security_level = may
smtp_tls_loglevel = 1
パスワードファイル作成
# vi /etc/postfix/smtp-auth-passwd
[smtp.gmail.com]:587 xxxxxx@gmail.com:PASSWORD
パスワードファイルからデータベースを作成
# postmap /etc/postfix/smtp-auth-passwd
Postfix 再起動
# /etc/init.d/postfix restart
動作確認

Mailx インストール

# yum -y install mailx

Mail コマンド

# echo "test" | mail -s "test" xxxxx@gmail.com

Gmail へメールが送信できます。

以上