CentOS6.xでGmailをpostfixでリレーしてメール送信する
今更?
ローカル環境にはあるけど一応、アウトプットしておく
Postfixをインストールしなくてもあった
[root@localhost ~]# which postfix /usr/sbin/postfix [root@localhost ~]#
必要そうなパッケージをインストールして起動
yum -y install cyrus-sasl-plain cyrus-sasl-md5 service saslauthd start chkconfig saslauthd on
telnetもない場合はインストール
yum install -y telnet
465で接続
[root@localhost ~]# telnet smtp.gmail.com 465 Trying 173.194.72.109... Connected to smtp.gmail.com. Escape character is '^]'. ehlo localhost Connection closed by foreign host. [root@localhost ~]#
???
587で接続
root@localhost ~]# telnet smtp.gmail.com 587 Trying 173.194.72.109... Connected to smtp.gmail.com. Escape character is '^]'. 220 mx.google.com ESMTP kh6sm8594346pbc.50 - gsmtp ehlo localhost 250-mx.google.com at your service, [180.46.248.13] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 quit 221 2.0.0 closing connection kh6sm8594346pbc.50 - gsmtp Connection closed by foreign host. [root@localhost ~]#
なんか587ならいけそうかも
postfix設定ファイルを編集
/etc/postfix/main.cf
##################################################################### relayhost = [smtp.gmail.com]:587 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_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt #####################################################################
※末尾に追記
ファイルを作成
echo [smtp.gmail.com]:587 username@gmail.com:password > /etc/postfix/sasl_passwd chmod 600 /etc/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd
※ユーザーとパスワードは自分のものを設定する
再起動
service postfix restart
メール送信
メール送信用のパッケージをインストール
yum -y install mailx
メールを送信する
echo hogehoge | mail username@gmail.com
終わり