Postfixを使ってGmailアカウントのメールを送る [Server software]
サーバーでPostfixを動かして、自分のGmailアカウントのメールを送るための設定です。
これでローカルでroot宛てに届いたメールをGmailアカウント宛てに転送することもできます。
Zabbixのアラートメールも送れます。
まずは、Postfixのインストールから。ちなみに、サーバーはUbuntu11.10
# apt-get install postfix
Gmailでメールを送るためには、TLS/SSLが必要なので、sasl2-binもインストール。
# apt-get install sasl2-bin
次に設定。
# vi /etc/postfix/main.cf
--
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
myorigin = localhost.localdomain
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
delay_warning_time = 1h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls=yes
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = ws # サーバー名に書き換えます
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = ws, localhost.localdomain, localhost # サーバー名を追記
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost
home_mailbox = Maildir/
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_auth
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
relay_domains = gmail.com
smtpd_recipient_restrictions = permit_auth_destination,reject
--
sasl_auth を新たに作成します。Gmailアカウントの設定です。
# vi /etc/postfix/sasl_auth
--
[smtp.gmail.com]:587 example@gmail.com:password
--
パスワードファイルの読み書き権限を変更します。
# chmod 600 /etc/postfix/sasl_auth
パスワードファイルをハッシュ化します。
# postfix /etc/postfix/sasl_auth
最近のpostfixでは、postfixコマンドの代わりに、postmapコマンドを使うようです。(2013/9/16追記)
これで、/etc/postfix/sasl_auth.dbが作成されたはずです。
# service postfix restart
これでおわり。
root宛てのメールをexample@gmail.com宛てに転送する設定は/etc/aliasesから。
# vi /etc/aliases
--
root: example@gmail.com
--
ハッシュ化。
# newaliases
これで送れるはずですが。。
ところで、ログが、/var/log/syslogと/var/log/mail.log両方に同じものがはかれているので、設定を変更します。
# vi /etc/rsyslog.d/50-default.conf
--(変更前)
(略)
*.*;auth,authpriv.none -/var/log/syslog
(略)
--
↓
--(変更後)
(略)
*.*;mail,auth,authpriv.none -/var/log/syslog
(略)
--
# service rsyslog restart
Done!
タグ:リレー