LoginSignup
103
112

More than 5 years have passed since last update.

AWS上にメールサーバを立てる(Postfix+Dovecot)

Last updated at Posted at 2015-02-28

メール使いますよ申請

申請

申請が通ると以下のようなメールが

Hello,

We have configured the reverse DNS record(s) you requested. Your request was mapped for [IPアドレス]:[メールサーバFQDN]. Please note that propagation of this update to DNSBL services that Amazon works with may take up to a week.

If you also requested removal of the email sending limitations on your account, these have also been removed for any IPs and instances under your account.

Please let us know if you have any questions.

Thank you for your inquiry. Did I solve your problem? 

If yes, please click here: 
http://www.amazon.com/gp/help/survey?p=APN87EQ3BRVQS&k=hy 

If no, please click here: 
http://www.amazon.com/gp/help/survey?p=APN87EQ3BRVQS&k=hn

Best regards,


http://aws.amazon.com

---- Original message: ----

AWS AccountId             [AWSアカウントID]
AccountEmailAddress         [登録メールアドレス]
UseCaseDescription          send mail
ElasticIPAddress1           [メールサーバとしているEC2のElasticIP]
ElasticIPAddress2            
ReverseDNSRecord1           [外部に登録したDNSレコード]
ReverseDNSRecord2            

EC2の設定

・EC2インスタンスを建てる(Amazon Linux)
・セキュリティグループの以下を設定
  ssh、pop3、smtp

ドメインの登録

EC2からの送信に関しては特にドメイン登録は不要ですが、受信時やメーラに設定する場合はDNS登録が必要です。
私はお名前.comで99円ドメイン買いましたw

Postfixのインストール

インストールの実行
$ sudo yum -y install postfix

Postfixの設定
$ sudo vi /etc/postfix/main.cf

main.cf
# ※設定箇所のみ記述します。

# メールサーバのホスト名を設定
myhostname = [メールサーバのFQDN]

# メールアドレスで使用するドメインを設定
mydomain = [ドメイン名]

# ローカルからメールを送信した際の認識設定
myorigin = $myhostname

# ローカル以外からもメールを受信するように設定
inet_interfaces = all

# メールサーバが自分宛のメールであると認識するためのドメイン名を設定
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# 信頼するネットワークアドレス体系を設定
mynetworks = 10.0.0.0/16, 127.0.0.0/8

# メールを格納するフォルダの設定(ユーザのホーム配下のMaildirフォルダにメールを格納する記述)
home_mailbox = Maildir/

# メーラーからのSMTPを587番ポートでリレーする設定
relayhost = [メールサーバのFQDN]:587

# SMTPサーバの認証設定
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination

saslauthdの起動及び自動自動設定
$ sudo service saslauthd start
$ sudo chkconfig saslauthd on

メールをsendmailからPostfixに切り替え
$ sudo alternatives --config mta

There are 2 programs which provide 'mta'.

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

Enter to keep the current selection[+], or type selection number:2

sendmailの停止
$ sudo service sendmail stop
$ sudo chkconfig sendmail off

Postfixの起動及び自動設定
$ sudo service postfix start
$ sudo chkconfig postfix on

ユーザの作成
$ sudo useradd user
$ sudo passwd user

メールディレクトリの作成
$ sudo su - user
$ mkdir Maildir
$ exit

メール送信テスト

以下のように入力し、メールサーバ自身からメール送信テストをします。
失敗時は/var/log/maillogを確認します。

sendmail [送信したいメールアドレス]
From:[送信元アドレス(上記手順だと user@ホスト名+ドメイン)]
To:[送信したいメールアドレス]
Subject:テスト送信←題名

テスト送信です。←本文

. ←「.」を打つと送信される

Dovecotの設定

PCのメールソフトに構築したサーバを設定してメールをやり取りするには、Dovecotが必要なようです。
メーラでの状況
POP認証:OK
SMTP認証:OK
メール受信:OK
メール送信(自分のアドレス):OK
メール送信(別サーバのアドレス):NG・・・・

インストール
$ sudo yum install -y dovecot

保存先設定
$ sudo vi /etc/dovecot/conf.d/10-mail.conf

10-mail.conf
#保存場所をホームディレクトリ/Maildirに設定
mail_location = maildir:~/Maildir

認証設定
$ sudo vi /etc/dovecot/conf.d/10-auth.conf

10-auth.conf
#メーラからの認証をはじいてたみたいなので、「no」に変更
disable_plaintext_auth = no

#loginを追加
auth_mechanisms = plain login

送信用設定
$ sudo vi /etc/postfix/master.cf

以下の1行のコメントアウト(#)をはずす

master.cf
submission inet n       -       n       -       -       smtpd

認証情報の作成
sudo vi /etc/postfix/sasl_passwd

[メールサーバ名のFQDN]:587 [ユーザ名]:[パスワード]

パスワードDB生成
$ sudo postmap hash:/etc/postfix/sasl_passwd
$ sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
$ sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

起動及び自動起動設定
$ sudo service dovecot start
$ sudo chkconfig dovecot on

103
112
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
103
112