LoginSignup
2
4

More than 5 years have passed since last update.

CentOS6.9でpostfixを使ってGmail経由でメール送信する方法

Last updated at Posted at 2018-06-16

内容

DockerCentOS6.9のコンテナを起動し、
postfixGmailを経由してメール送信する方法を記載します。

Dockerを実行する環境に関しては構築済みと言う前提です。

参考サイト

環境

項目
OS Windows10
Vagrant 2.0.1
VM CentOS7
Docker 17.12.0-ce

流れ

  1. Gmailの設定
  2. DockerCentOS6.9のコンテナ起動
  3. コンテナにpostfix等をインストール
  4. /etc/postfix/main.cfを設定
  5. /etc/postfix/sasl_passwdを作成
  6. postfixのサービスを起動
  7. メール送信

1. Gmailの設定

以下のURLから「安全性の低いアプリ」を許可する
https://myaccount.google.com/lesssecureapps

2. DockerCentOS6.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: <適当なタイトル>
<メール本文>
.
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4