茨城県つくばみらい市から来ました

プログラマーになるために生きています

CentOS6でGmailサーバー経由でメールを送信しますので

CentOS6, Postfix.x86_64 2:2.6.6-2.1.el6_0なんです

設定ファイルをイジる

参考:Postfix で、Gmail にメールをリレーする - 私の二次記憶

[root@youpandora postfix]# diff main.cf main.cf.orig 
77d76
< myhostname = youpandora.motchang.myhome.cx
85d83
< mydomain = motchang.myhome.cx
102d99
< myorigin = $mydomain
167,168c164
< #mydestination = $myhostname, localhost.$mydomain, localhost
< mydestination = $myhostname, $mydomain, localhost.$mydomain, localhost, localhost.localdomain
---
> mydestination = $myhostname, localhost.$mydomain, localhost
322,330d317
< relayhost = [smtp.gmail.com]:587
< # debug_peer_list = smtp.gmail.com
< 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_security_options = noanonymous
< smtp_sasl_mechanism_filter = plain
< smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt

root@youpandora.motchang.myhome.cx宛のメールとroot@motchang.myhome.cx宛のメールをローカルとして扱う。外部に晒すようなことは考えていない。

パスワードファイルを作る

vim /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 ***@gmail.com:password

パスワードファイルのハッシュ化

postmap /etc/postfix/sasl_passwd

足りないパッケージを入れる

PLAINでログインする為に

yum install cyrus-sasl-plain

実はこれが一番の難所だったかもしれない

aliasを編集する

rootへのメール→一般アカウント→gmail

postfix再起動

/etc/init.d/postfix restart

テスト

mail root
mail ****@gmail.com

めも

myaccount@gmail.comをSMTPのアカウントに使うとして、myaccount@gmail.comへのメールを送信した場合送信済みフォルダに入ってしまうので、今回はmyaccount.alias@gmail.comみたいなアカウントを新しくとって転送用アカウントにした。Postfixさんマジゆるふわっす。