keimlab’s diary

KEIMLABの電気・電子・制御の開発備忘録と日常生活記録

メールサーバーの設定①

はじめに

メールサーバーを設定しようとしたときの記録です。

環境

Raspberry Pi 2 Model B
Ubuntu Mate 18.04

Postfixのインストール・設定

1.postfixをインストールする
sudo apt-get install -y postfix

2.main.cfを編集する
sudo vi main.cf

mail_owner = postfix
myhostname = mail.hogefuga.com
mydomain = hogefuga.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
local_recipient_maps = unix:passwd.byname $alias_maps
# mynetworks = 127.0.0.0/8 ←コメント化 mynetworks_style = subnet
mynetworks = 127.0.0.0/8, 192.168.1.1/24
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
sendmail_path = /usr/sbin/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
#html_directory = ←コメント化
# manpage_directory = ←コメント化
#sample_directory = ←コメント化
# readme_directory = ←コメント化

relayhost = [mail.so-net.ne.jp]:587
sudo vi /etc/postfix/relay_password
transport_maps = hash:/etc/postfix/transport
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous

3.メールエイリアスのデータベースを再構築する sudo newaliases

4.postmap
postmap hash:/etc/postfix/relay_password

5.postfx
sudo /etc/init.d/postfix restart

6.mailutilsをインストール
sudo apt-get install mailutils

7.メールを送信するテスト
mail hogehoge@gmail.com
Cc:
Subject:
test
"Ctrl + d"

上記にて、Gmailアカウントにメールが送信されればOK

#参考文献 qiita.com www.maruko2.com