LoginSignup
24
26

More than 5 years have passed since last update.

5分で出来るお手軽メール転送サーバ

Posted at

まずは…

サーバを準備する

AWS EC2を利用する。
-AmazonLinux
-t2.micro
-StorageはMagnetic
-SecurityGroup設定
--SSH TCP 22 0.0.0.0/0
--SMTP TCP 25 0.0.0.0/0

ドメインを用意する

-ドメイン取得する(お名前.com等で)
-レコード設定
--Aレコード:hogehoge.com / 111.111.111.111(用意したEC2のIP)
--MXレコード:hogehoge.com / 10 hogehoge.com

インストール

$ sudo yum install postfix -y


各種設定

$ sudo vi /etc/postfix/main.cf
myhostname = hogehoge.com
mydomain = hogehoge.com
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
alias_maps = hash:/etc/aliases,regexp:/etc/postfix/aliases.reg



hoge@hogehoge.comに対してhoge+xxx@hogehoge.comが使えるようにする

$ sudo vi /etc/postfix/aliases.reg
/^hoge+[^@]+(@.*)?$/ hoge



転送設定(例としてgmailに転送)

$ sudo vi /etc/aliases
hoge    hoge@gmail.com
$ sudo newaliases



メールを受信出来るようにする

$ sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT
$ sudo /etc/init.d/iptables save
$ sudo service iptables restart



sendmailからの切り替え

$ sudo /etc/rc.d/init.d/saslauthd start
$ sudo chkconfig saslauthd on
$ sudo /etc/rc.d/init.d/sendmail stop
$ sudo chkconfig sendmail off
$ sudo alternatives --config mta
 -> postfixを選択
$ sudo /etc/rc.d/init.d/postfix start
$ sudo chkconfig postfix on



動作確認

hoge@hogehoge.comにメールを送信してみてください。
hoge@gmail.comに届けば成功です。

24
26
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
24
26