Postfixとは
postfixとはメールサーバとして広く一般的に利用されているものです。 このサーバを構築することによって、自宅サーバをメールサーバとして運用することができ
自分で取得したドメインによるE-mailアドレスを好きなだけ発行することができるようになります。
今回は基本的なpostfixの設定と
サーバよりメールを発送することまでを行います。
設定
まずAPTよりインストールを行います。
# aptitude update
# aptitude install postfix
そうすると対話式設定が表示されますので以下のようにします。# aptitude install postfix
Postfix Configuration インターネットサイト メール名? あなたのドメインを入力(ex)hogehoge.com
■ リレー可能な範囲の指定
家庭内LANの範囲も許可します。
# 34行目付近
mynetworks = 127.0.0.0/8
↓
mynetworks = 192.168.0.0/24, 127.0.0.0/8
mynetworks = 127.0.0.0/8
↓
mynetworks = 192.168.0.0/24, 127.0.0.0/8
■ メールの保存形式の変更
# 36行目付近追加
home_mailbox = Maildir/
# 38行目付近
mailbox_command = procmail -a "$EXTENSION"
↓
#mailbox_command = procmail -a "$EXTENSION"
これを追加することにより、各ユーザのメールはhome_mailbox = Maildir/
# 38行目付近
mailbox_command = procmail -a "$EXTENSION"
↓
#mailbox_command = procmail -a "$EXTENSION"
各々のホームディレクトリの「Maildir」フォルダ以下に保存されるようになります。
そのため既存のユーザではホームディレクトリに「Maildir」フォルダを作成する必要があります。
また、これから新規で作るユーザで毎回「Maildir」を作る手間を省くために
# mkdir /etc/skel/Maildir
としておきます。これでこれ以降作成するユーザのホームディレクトリには「Maildir」が作成されています。 ■ ファイル全体
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
###ホスト名の指定
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
###新着メールの通知をしない
biff = no
# appending .domain is the MUA's job.
###ドメインの追加を無効にする
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
###SSLの設定
# TLS parameters
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_cert_file=/etc/ssl/private/server.crt
smtpd_tls_key_file=/etc/ssl/private/server.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
###ホスト名の指定
myhostname = rainlib.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
###ドメインの設定(@以下の部分)
myorigin = /etc/mailname
###許可するドメインの指定
mydestination = rainlib.com, localhost
###リレーの設定
relayhost =
mynetworks = 127.0.0.0/8, 192.168.0.0/24
###メールの保存形式
home_mailbox = Maildir/
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
###ホスト名の指定
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
###新着メールの通知をしない
biff = no
# appending .domain is the MUA's job.
###ドメインの追加を無効にする
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
###SSLの設定
# TLS parameters
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_cert_file=/etc/ssl/private/server.crt
smtpd_tls_key_file=/etc/ssl/private/server.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
###ホスト名の指定
myhostname = rainlib.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
###ドメインの設定(@以下の部分)
myorigin = /etc/mailname
###許可するドメインの指定
mydestination = rainlib.com, localhost
###リレーの設定
relayhost =
mynetworks = 127.0.0.0/8, 192.168.0.0/24
###メールの保存形式
home_mailbox = Maildir/
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
以上で設定は完了です。postfixに設定をリロードさせます。
/etc/init.d/postfix force-reload
動作テスト
「mail」コマンドを使用し、サーバ上よりメールを送信してみます。
# mail 宛先メールアドレス
次に件名を聞いてきますので入力します。
# Subject: test
次に本文の入力です。これは最後に「.」を打つことで入力を完了します。 そして最後に「CC」を入力します。特に必要なければ何も入力しなくてOKです。
以上で作業は完了です。
入力した宛先メールアドレスよりメールを受信してみてください。
入力した件名・文章が届けばOKです。