内容
Docker
でCentOS6.9
のコンテナを起動し、
postfix
でGmail
を経由してメール送信する方法を記載します。
Docker
を実行する環境に関しては構築済みと言う前提です。
参考サイト
環境
項目 | |
---|---|
OS | Windows10 |
Vagrant | 2.0.1 |
VM | CentOS7 |
Docker | 17.12.0-ce |
流れ
-
Gmail
の設定 -
Docker
でCentOS6.9
のコンテナ起動 - コンテナに
postfix
等をインストール -
/etc/postfix/main.cf
を設定 -
/etc/postfix/sasl_passwd
を作成 -
postfix
のサービスを起動 - メール送信
1. Gmail
の設定
以下のURLから「安全性の低いアプリ」を許可する
https://myaccount.google.com/lesssecureapps
2. Docker
でCentOS6.9
(以降コンテナ)のコンテナ起動
$ docker run --rm -it centos:6.9 bash
3. コンテナにpostfix
等をインストール
[centos6.9]# yum update -y
[centos6.9]# yum install -y postfix cyrus-sasl-plain mailx
4. /etc/postfix/main.cf
を設定
[centos6.9]# vi /etc/postfix/main.cf
# 以下2点は変更
inet_interfaces = localhost
↓
inet_interfaces = all
inet_protocols = all
↓
inet_protocols = ipv4
# ファイル末尾に追記
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt
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
5. /etc/postfix/sasl_passwd
を作成
- ファイル作成
[centos6.9]# vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 <Gmailのメールアドレス>:<Gmailのログインパスワード>
- DB化
[centos6.9]# chmod 600 /etc/postfix/sasl_passwd
[centos6.9]# postmap /etc/postfix/sasl_passwd
6. postfix
のサービスを起動
[centos6.9]# service postfix start
7. メール送信
[centos6.9]# mail <送信先のメールアドレス>
Subject: <適当なタイトル>
<メール本文>
.