Postfix で Gmail を relayhost にする (Ubuntu)

前回は、CentOS 用の設定を書いたのですが、個人的には、Ubuntu を触ることのほうが多いので、設定方法をメモしておきます。

あらかじめ、MTA を postfix に変更済と想定。

  1. 必要なパッケージをインストール。
    $ sudo apt-get install sasl2-bin
  2. postfix の設定ファイルを編集
    $ sudo vi /etc/postfix/main.cf
  3. 以下の内容を追記
    relayhost = [smtp.gmail.com]:587
    #sasl setting
    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 = plain
    #tls setting
    smtp_use_tls = yes
  4. /etc/postfix/sasl_passwd を作成(メールアドレスやパスワードは各自のものを)
    vi /etc/postfix/sasl_passwd
    [smtp.gmail.com]:587 username@gmail.com:password
  5. /etc/postfix/sasl_passwd の権限変更
    # chown root:root /etc/postfix/sasl_passwd
    # chmod 600 /etc/postfix/sasl_passwd
  6. hash形式の /etc/postfix/sasl_passwd.dbを作成
    # postmap /etc/postfix/sasl_passwd
  7. postfixの再起動
    # /etc/init.d/postfix restart
  8. で、適当に sendmail などでメールを送信してみて確認してみる。

| コメントは受け付けていません。 | etc..., tech