メールサーバーの構築
ここではメールサーバーの構築をして好きなメールアドレスを発行してメールが使えるようにします。
じんたろうは2つのドメインを持っていますのでバーチャルドメインの設定もします。
SMTPサーバー(送信用)には「Postfix」
POPサーバー(受信用)には「Dovecot」
を使用します。
Fedora8にはSMTPサーバーとして「Sendmail」がデフォルトでインストールされて起動していますが、
設定が難しい(らしい)のでPostfixを使用する事にします。
送信に関しては通常プロバイダ等では POP before SMTP という方式が多いみたいですが(SMTP自体で認証しない)
SPAMメールの踏み台にされるのを防ぐ為、ここでは SMTP-AUTH を使いSMTP自体に認証機能を持たせます。
- メールアドレス(@より左の部分)とパスワードに関しては設定が簡単な為、通常のLinuxユーザー名と共用します。
- メールボックスの形式はMaildir形式とします。(/home/ユーザー名/Maildirにメールが届く)
Postfixのインストール
SMTPサーバー(送信サーバー)のPostfixをyumでインストールします。
[root@jintaro ~]# yum -y install postfix
(中略)
Installed: postfix.i386 2:2.4.5-2.fc8
Complete!
[root@jintaro ~]#
|
Postfixをインストール
インストール完了
|
Postfixの設定
Postfixのメインの設定ファイルを開いて編集します。
[root@jintaro ~]# vi /etc/postfix/main.cf
(中略)
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = jintaro.jintaro.com
(中略)
#mydomain = domain.tld
mydomain = jintaro.com
(中略)
#myorigin = $myhostname
#myorigin = $mydomain
↓
myorigin = $mydomain
(中略)
inet_interfaces = localhost
↓
inet_interfaces = all
(中略)
mydestination = $myhostname, localhost.$mydomain, localhost
↓
#mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
(中略)
#relayhost = $mydomain
#relayhost = [gateway.my.domain]
#relayhost = [mailserver.isp.tld]
#relayhost = uucphost
#relayhost = [an.ip.add.ress]
relayhost = [smtp.nifty.com]
(中略)
#home_mailbox = Maildir/
↓
home_mailbox = Maildir/
---最終行へ追加ここから---
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 10485760
---最終行へ追加ここまで---
|
Postfixの設定ファイルを開く
←追加 サーバーのホスト名
←追加 自ドメイン名
←変更 #をはずして有効化
←変更
外部からの送信も許可
←変更 #でコメントアウト
←変更 #をはずして有効化
自ドメイン宛メールを受信できるようにする
←追加 リレーするSMTPサーバー名(注1)
←変更 #をはずして有効化
メールボックスをMaildir形式にする
SMTP-AUTH設定
メッセージサイズ上限(10MB)
|
(注1)OP25B対策
サーバーが接続しているプロバイダのSMTPサーバーを指定します。(ここでは@nifty)
当方では指定しないと送れませんでした。
SMPT-AUTHの設定
[root@jintaro ~]# service saslauthd start
saslauthd を起動中: [ OK ]
[root@jintaro ~]# chkconfig saslauthd on
[root@jintaro ~]# chkconfig --list saslauthd
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@jintaro ~]#
|
saslauthdを起動
自動起動on
自動起動確認
2〜5でon
|
メール用ディレクトリの作成
既存ユーザーのメール用のディレクトリを作成します。
ここでは例としてtestuserというユーザーがいるものとします。
[root@jintaro ~]# mkdir -p /home/testuser/Maildir/new
[root@jintaro ~]# mkdir -p /home/testuser/Maildir/cur
[root@jintaro ~]# mkdir -p /home/testuser/Maildir/tmp
[root@jintaro ~]# chown -R testuser:testuser /home/testuser/Maildir
[root@jintaro ~]# chmod -R 700 /home/testuser/Maildir
|
メール用ディレクトリ作成
メール用ディレクトリ作成
メール用ディレクトリ作成
メール用ディレクトリの所有者変更
メール用ディレクトリのパーミッション変更
|
新規に作成したユーザーにメール用ディレクトリが自動的に作成されるようにします。
/etc/skel/ にディレクトリを作成しておくと新規ユーザー作成時に自動的に /home/ユーザー名/ 以下に同じディレクトリが作成されます。
[root@jintaro ~]# mkdir -p /etc/skel/Maildir/new
[root@jintaro ~]# mkdir -p /etc/skel/Maildir/cur
[root@jintaro ~]# mkdir -p /etc/skel/Maildir/tmp
[root@jintaro ~]# chmod -R 700 /etc/skel/Maildir
|
新規ユーザーのメール用ディレクトリ作成
新規ユーザーのメール用ディレクトリ作成
新規ユーザーのメール用ディレクトリ作成
新規ユーザーのメール用ディレクトリのパーミッション変更
|
Postfixの起動
デフォルトで立ち上がっているSendmailを停止してPostfixを起動します。
[root@jintaro ~]# service sendmail stop
sm-client を停止中: [ OK ]
sendmail を停止中: [ OK ]
[root@jintaro ~]# chkconfig sendmail off
[root@jintaro ~]# chkconfig --list sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@jintaro ~]# alternatives --config mta
2 プログラムがあり 'mta' を提供します。
選択 コマンド
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
[root@jintaro ~]# service postfix start
postfix を起動中: [ OK ]
[root@jintaro ~]# chkconfig postfix on
[root@jintaro ~]# chkconfig --list postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
Sendmailを停止
Sendmailの自動起動off
自動起動off確認
1〜6でoff
メールサーバーを切り替え
2でPostfixを選択
Postfix起動
Postfix自動起動on
自動起動確認
2〜5でon
|
Dovecotのインストール
POPサーバー(受信サーバー)のDovecotをyumでインストールします。
[root@jintaro ~]# yum -y install dovecot
(中略)
Installed: dovecot.i386 1:1.0.10-4.fc8
Complete!
|
Dovecotインストール
インストール完了
|
Dovecotの設定
Dovecotの設定ファイルを開いて編集します。
[root@jintaro ~]# vi /etc/dovecot.conf
(中略)
#protocols = imap imaps pop3 pop3s
↓
protocols = imap imaps pop3 pop3s
(中略)
#mail_location =
mail_location = maildir:~/Maildir
|
設定ファイルを開く
←変更
#を外して有効化
←追加
メールボックスをMaildir形式にする
|
Dovecotの起動
[root@jintaro ~]# service dovecot start
Dovecot Imap を起動中: [ OK ]
[root@jintaro ~]# chkconfig dovecot on
[root@jintaro ~]# chkconfig --list dovecot
dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
Dovecotを起動
Dovecot自動起動on
自動起動確認
2〜5でon
|
バーチャルホストの設定 (ドメインが2つ以上ある場合のみ)
バーチャルホストの設定をします。(ドメインまたはサブドメインが複数ありそのドメインでもメール送受信したい場合)
例として
メインのドメイン → jintaro.com
もうひとつのドメイン → hoge.com
として説明します。
[root@jintaro ~]# vi /etc/postfix/virtual
hoge.com anything
@hoge.com @jintaro.com
[root@jintaro ~]# postmap /etc/postfix/virtual
[root@jintaro ~]# vi /etc/postfix/main.cf
virtual_maps = hash:/etc/postfix/virtual
[root@jintaro ~]# service postfix restart
postfix を停止中: [ OK ]
postfix を起動中: [ OK ]
|
Postfixのバーチャルドメイン設定ファイルを編集
←この2行を最終行に追加
バーチャルドメイン設定反映
Postfixメイン設定ファイル編集
←最終行に追加
Postfixを再起動
|
この設定で
aaa@hoge.com 宛てのメールは aaa@jintaro.com へ転送されるようになります。Linuxユーザーの aaa が受け取る事になります。
bbb@hoge.com 宛てのメールは bbb@jintaro.com へ転送されるようになります。Linuxユーザーの bbb が受け取る事になります。
クライアント側メールソフトのメールアドレスは jintaro.com と hoge.com のどちらでも送受信できます。
(メールボックスは共用してます。)
ポート開放及び不正中継テスト重要!
外部から使用できるようにするにはルータの25番と110番ポートを開きます。
上記ポートを開いたら必ず以下の不正中継テストを行いましょう。
メールサーバーの不正中継テスト
クライアントのメールソフトの設定
Outlook Express 6 の場合
「全般」タブでメールアドレスを入力します。
(バーチャルドメインを設定している場合はどちらのドメインでも良い)
「サーバー」タブで
「受信メール(POP3)」
「送信メール(SMTP)」
それぞれドメイン名を入力
「アカウント名」は存在するLinuxユーザー名を入力
「パスワード」はLinuxユーザーのログインパスワードを入力
「このサーバーは認証が必要」にチェック
「設定」ボタンを押す
「受信メールサーバーと同じ設定を使用する」を選択
Becky! の場合
「基本設定」タブで
「メールアドレス」を入力
「POPサーバー」、「SMTPサーバー」
にそれぞれドメイン名を入力
「ユーザーID」は存在するLinuxユーザー名を入力
「パスワード」はLinuxユーザーのログインパスワードを入力
「詳細」タブで
「SMTP認証」にチェック
「ユーザーID」、「パスワード」は
POP用を使うので省略
OP25B対策
2009年9月3日に外部(OCN経由)で送信が出来なくなりました。
その時の対処法はこちら。
|