Home arrow Downloads
Main Menu
Home
Blog
Downloads
Forum
Link
Search
Category
Mobile
PHP
Google
Joomla
Cygwin
I-Apply
Linux
Plagger
Internet
Other
What's New
Recommend
RSS
E-Pagerank
Postfixで、GMAIL経由でメールを送る(OP25B対策) PDF プリント メール
Writte by Administrator   
2007/01/22 月曜日 12:01

Postfixで、GMAIL経由でメールを送る(OP25B対策)

しばらく前から、サーバからメールが送れない現象が続いてた。
なんらかの設定を変えてしまったせいなのかと思っていた。

時間もなかったことで、調べずに放置していたのだがPlaggerを
入れたのをきっかけで調べてみた。(PlaggerでGMAILにメールを
送信したかった)


調べたところ、どうやらサーバの設定ではなくOP25Bのせいだと
いうことがわかった。

そこで、OP25B対策としてGMAILを経由してメールを送信する
ように設定を変更した。

OP25Bについてはこちら


ログを見ながら進めた作業内容を書いているため、解りにくくなってるいるために、
さくっと、設定をしたい場合はまとめ(ページ最後)を見るといいかもです

Postfixの設定変更

まず、Postfixの設定ファイルに、GMAIL経由でメールを送信
するように設定を行う。

sasl_passwdファイルの作成

sasl_passwd(任意のファイル名でOK)というファイルを作成し、
そこにGMAILのSMTPサーバ、ユーザ名、パスワードを記述する。

$ cd /etc/postfix
$ vim sasl_passwd

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


sasl_passwdファイルをpostmapコマンドを使い、DB化

$ postmap sasl_passwd

main.cfの書き換え
$ cp main.cf main.cf.bak
$ vim main.cf

# (以下を追加)
relayhost=[smtp.gmail.com]:587

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_mechanism_filter = plain


Postfixの設定変更反映

$ /etc/init.d/postfix reload


メールを送信してみる

メールを送信するのに以下のような適当なシェルとメール本文を
作成してメールの送信テストを行った。


$ vim testsendmail.sh
#!/bin/bash
cat test.mail |iconv -f eucJP -t ISO-2022-JP | /usr/sbin/sendmail -t -oi

$ vim test.mail
From: このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい
To: このメールアドレスはスパムボットから保護されています。観覧するにはJavaScriptを有効にして下さい
Subject: test
Mime-Version: 1.0
Content-type: text/plain; charset=iso-2022-jp

test hogehoge


TLSの設定
送ってみたものの、どうも上手く送信できていないようだ。
ということで、ログを見てみる。

$ tail -f /var/log/maillog


そこで以下の様なメッセージが出力されていた。

Must issue a STARTTLS command first i16sm1895070wxd


どうやら、うまくTLSでGMAILとのやりとりが出来ていないようである。
ということで、よくも解らず以下のコマンドを行ってみた。

$ apt-cache search sasl
$ apt-get install cyrus-sasl

(インストール済みだった)


どうも調べてみると、TLSの設定というのが必要なようである。
そこで、Postfixの設定で以下を追加してやった。

$ vim /etc/postfix/main.cf
(以下を追加)
#tls setting
smtp_use_tls = yes

再度メール送信

再度メールを送信してみるもののこれでもやはり、メールが
送信出来ていなかった。


ログを確認してみると以下のように出力されている。
(編集してあります)

 
> gmail-smtp.l.google.com[64.233.185.111]: EHLO [server domain]
 < gmail-smtp.l.google.com[64.233.185.111]: 250-mx.google.com at your service, [125.197.170.81]
 < gmail-smtp.l.google.com[64.233.185.111]: 250-SIZE 20971520
 < gmail-smtp.l.google.com[64.233.185.111]: 250-8BITMIME
 < gmail-smtp.l.google.com[64.233.185.111]: 250-AUTH LOGIN PLAIN
 < gmail-smtp.l.google.com[64.233.185.111]: 250 ENHANCEDSTATUSCODES
 match_string: LOGIN ~? plain
 match_list_match: LOGIN: no match
 match_string: PLAIN ~? plain
 server features: 0x102b size 20971520
 maps_find: smtp_sasl_passwd: hash:/etc/postfix/sasl_passwd(0,100): gmail-smtp.l.google.com = [username]@gmail.com:[password]
 smtp_sasl_passwd_lookup: host `gmail-smtp.l.google.com' user `[username]@gmail.com' pass `[password]'
 starting new SASL client
 name_mask: noanonymous
 smtp_sasl_authenticate: gmail-smtp.l.google.com[64.233.185.111]: SASL mechanisms PLAIN
 warning: SASL authentication failure: No worthy mechs found
 A59CF163B7E: Authentication failed: cannot SASL authenticate to server gmail-smtp.l.google.com[64.233.185.111]: no mechanism available
 > gmail-smtp.l.google.com[64.233.185.111]: QUIT

このログを見ると、どうやらAUTHがのメカニズムがGMAILとこちらで
マッチしていないようである。

GMAILから要求されいてうるAUTHが
LOGIN PLAINである。
 < gmail-smtp.l.google.com[64.233.185.111]: 250-AUTH LOGIN PLAIN
(上記ログより) 


こちらの設定では、PLAINに設定がされている。

smtp_sasl_mechanism_filter = plain
(main.cfより)


「no mechanism available」とログが出力されていることから、
本当にPLAINが入っているのかということで確認をしてみる。


Cyrus sasl plinのインストール


$ apt-cache search cyrus
$ apt-get install cyrus-sasl-plain


ということで、インストール後にメールを送信したところ、
無事メールが送信できるのが確認できた。

 

まとめ

わかりにくくなってしまったために、行った作業についてまとめを行う。


sasl_passwd作成
$ vim /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [username]@gmail.com:[password]

sasl_passwdのdb化
$ postmap sasl_passwd

main.cfの設定追加
$ vim /etc/postfix/main.cf
(以下の設定を追加)
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

cyrus-sasl-plainのインストール
$ apt-cache search cyrus
$ apt-get install cyrus-sasl-plain


* 補足
DEBUGログの見方
$ vim /etc/postfix/main.cf
(以下の設定を追加)
debug_peer_level = 2
#debug_peer_list = smtp.gmail.com
#debug_peer_list = gmail-smtp.l.google.com

 

Update ( 2007/01/22 月曜日 13:56 )
 
< 前へ   次へ >

© 2012 Labs Zsrv Net
Joomla! is Free Software released under the GNU/GPL License.
Translation is Joomla!JAPAN