« PostgreSQL インストール | メイン | CentOS 5.6 で VirtualBox 拡張機能を追加 »

OS

linuxでメール送信設定

 自ドメインで登録した google app の gmail でメール送受信を使用中。
この gmail の smtpサーバを使い virtualBOX の linuxサーバ localhost.localdomain から(自ドメインで)メールを送信する。

Postfix(CentOS6.7) → YahooBB(ADSL8M) → gmailのSMTP → internet

前提環境
$ cat /etc/redhat-release
CentOS release 6.7 (Final)
$ cat /proc/version
Linux version 2.6.32-573.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Thu Jul 23 15:44:03 UTC 2015
$ postconf | grep mail_version
mail_version = 2.6.6
手順は...▼
●OSが使用するMTA(Mail Transfer Agent)を確認。
$ sudo alternatives --config mta

There is 1 program that provides 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number:
●MTA(Mail Transfer Agent)のソフトウェアであるPostfixが稼働しているか確認。
$ sudo service postfix status
master (pid  1890) is running...
●Postfix起動
$ sudo service postfix restart
●Postfixの自動起動設定を確認。
$ chkconfig --list | grep postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
●必要であればPostfixの自動起動設定に変更。
$ sudo chkconfig postfix on
●送信試験する為にメールコマンドのインストール
$ sudo yum install mailx
送信コマンド例
echo "本文" | mail -s "タイトル" -r from@example.com -c cc1@example.com -c cc2@example.com to1@example.com to2@example.com
この時点ではプロバイダの制限で送信できない。
●メールキューの確認方法
$ mailq
●メールキューの削除方法
sudo postsuper -d ALL
●postfixのログファイルを監視して動きを確認する方法
$ sudo tail -f /var/log/maillog
ヤフーADSLなどのプロバイダーで接続している環境からもメール送信できるようにする。
$ sudo yum -y install cyrus-sasl-plain
●postfix設定ファイルの修正
$ sudo mv /etc/postfix/main.cf /etc/postfix/main.cf.org
$ sudo cp /etc/postfix/main.cf.org /etc/postfix/main.cf
$ sudo vi /etc/postfix/main.cf
$ sudo diff /etc/postfix/main.cf.org /etc/postfix/main.cf
317a318,324
> 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_sasl_mechanism_filter = plain
> smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt
●設定ファイルのチェック
$ sudo postfix check
●自ドメインgmailアカウントの設定
$ sudo vi /etc/postfix/sasl_passwd
アカウントが admin@mydomain、パスワードが mypass なら
[smtp.gmail.com]:587 admin@mydomain:mypass
●認証ファイルハッシュ化
$ sudo postmap /etc/postfix/sasl_passwd
●ファイルの読み出し制限
$ sudo chmod go-r /etc/postfix/sasl_passwd
$ sudo chmod go-r /etc/postfix/sasl_passwd.db
●postfix設定ファイルの反映
$ sudo service postfix reload
これで送信が可能になる。

下記は不要
sudo service saslauthd start

トラックバック

このエントリーのトラックバックURL:
https://www.remix.asia/cgi/mt/mt-tb.cgi/7495

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)