皆さんが通常使っている電子メールについて、簡単にご説明します。
電子メールの送受信をする為に、プロバイダから指定されているSMTPサーバ・POPサーバという欄を見たことがありませんか?
このSMTPサーバとPOPサーバとは何でしょう?
postfixはSMTPの機能を持っています。ここでは、このpostfixを構築する方法をご紹介いたします。
また、グローバルから外部宛メールを送信できるようにSMTP-Authをもたせる事とします。(不正中継利用の防止)
POPサーバ(受信メールサーバ)を構築するにはメールサーバ(POP/IMAP)の構築(Dovecot)をご覧ください。
      # yum -y install postfix  | 
    
      設定ファイルの編集
# vi /etc/postfix/main.cf
ホスト名を設定する(ホスト名.ドメイン名)
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
myhostname = fedora.kajuhome.com
ドメイン名を設定する
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
mydomain = kajuhome.com
送信者メールアドレスの@以降をドメイン名にする
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites.  If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
myorigin = $mydomain
Postfix が待ち受けるべき全てのネットワークインターフェースを指定
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on.  By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
inet_interfaces = all
Postfixが使用するプロトコルをIPv4に変更
# Enable IPv4, and IPv6 if supported
inet_protocols = ipv4
メールをローカルで受信するドメイン名を指定(ドメイン全体のメールサーバ)
# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
        :
        :
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
信頼されたネットワークをCIDR (network/mask) 表記で指定(ローカルネットワーク)
# Alternatively, you can specify the mynetworks list by hand, in
# which case Postfix ignores the mynetworks_style setting.
#
# Specify an explicit list of network/netmask patterns, where the
# mask specifies the number of bits in the network part of a host
# address.
#
# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
mynetworks = 192.168.1.0/24, 127.0.0.0/8
中継を許可するドメインを指定
# The relay_domains parameter restricts what destinations this system will
# relay mail to.  See the smtpd_recipient_restrictions restriction in the
# file sample-smtpd.cf for detailed information.
        :
        :
# NOTE: Postfix will not automatically forward mail for domains that
# list this system as their primary or backup MX host. See the
# permit_mx_backup restriction in the file sample-smtpd.cf.
#
relay_domains = $mydestination
メールボックス(Maildir)を各ユーザのホームディレクトリに配置
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user.  Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
home_mailbox = Maildir/
これ以降は、最下位行に追加
SMTPのVRFYコマンドを使用禁止
disable_vrfy_command = yes
VRFYはアカウントが実在するか確認するコマンドです。でたらめなユーザ問い合わせを行う悪質なプログラムにより
アカウント流出を防ぎます。
メール送信時にアカウント名・パスワードをサーバに通知しメールサーバから認証を受ける(SASL認証)
smtpd_sasl_auth_enable = yes
sasl認証に対応していないメーラは拒否
broken_sasl_auth_clients = yes
クライアントに対しての認証設定
smtpd_sasl_security_options = noanonymous
認証に使用するサーバを指定
smtpd_sasl_local_domain = $mydomain
            または (*1)
smtpd_sasl_local_domain = $myhostname
*1:メールアドレスの「@」以降の部分(当サイトであれば「kajuhome.com」に当たる)によって変更する。
(SMTP認証に失敗する場合に切り替えて見てください。)
       | 
    
      新規ユーザを作成した場合、メールボックス(Maildir)を作成する様にする # mkdir /etc/skel/Maildir # chmod 700 /etc/skel/Maildir 既存ユーザのメールボックス(Maildir)を作成する(例:linuxユーザの場合) 一度設定すれば構いません。 # mkdir /home/linux/Maildir 既存ユーザ(linux)のメールボックス(Maildir)のパーミッション・オーナ・グループ変更パーミッション変更 # chmod 700 /home/linux/Maildir オーナ・グループ変更 # chown linux:linux /home/linux/Maildir  | 
    
既存のアカウント(ユーザ)のパスワードとSMTP-Authパスワードを別にする場合です。
SMTP-Authパスワードを明示的にしたい場合に設定して下さい。(推奨)
      【Fedora14以降 / CentOS6以降 の場合】
設定ファイルの変更
# vi /etc/sasl2/smtpd.conf
pwcheck_method: auxprop
先頭に「#」を付けてコメント化
#mech_list: plain login
【上記以外の場合】
設定ファイルの変更(32bit版の場合)
# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: auxprop
先頭に「#」を付けてコメント化
#mech_list: plain login
設定ファイルの変更(64bit版の場合)
# vi /usr/lib64/sasl2/smtpd.conf
pwcheck_method: auxprop
先頭に「#」を付けてコメント化
#mech_list: plain login
*:1.「32bit版」と「64bit版」では修正するファイルが違うので注意して下さい。
   下記の「メール送信時に以下のメッセージが表示されメール送信できない場合」の様に
   正しくメール送信できません。
既存ユーザ(linux)のSMTP-Auth(送信認証)パスワード設定する
# saslpasswd2 -u kajuhome.com -c linux
パスワードを入力
Password:
確認入力(上記のパスワードと同じ物を入れる)
Again (for verification):
SMTP-Authユーザの確認
# sasldblistusers2
linux@kajuhome.com: userPassword
sasldb2のパーミッション・グループ変更
初期時、一度設定すれば構いません。
sasldb2の確認
# ll /etc/sasldb2
-rw-------  1 root root 12288  7月 21 05:21 /etc/sasldb2
    ↑              ↑
グループ読取(なし)    グループ(root)
パーミッション変更
# chmod 640 /etc/sasldb2
グループ変更
# chgrp postfix /etc/sasldb2
sasldb2の確認
# ll /etc/sasldb2
-rw-r-----  1 root postfix 12288  7月 21 05:21 /etc/sasldb2
       | 
    
      「smtpd.conf」の以下部分を再確認して下さい。 先頭に「#」を付けてコメント化 #mech_list: plain login *:変更した場合は設定を有効にする為、サービスを再起動して下さい。  | 
    
今後は、メールをpostfixで行なう為、デフォルトで起動されているsendmailを停止します。
また、システムデフォルトのMTAがsendmailとなっている為、postfixへ変更します。
      sendmailサービスの停止と自動起動解除
【FC1 から Fedora15 / CentOS4 / CentOS5 / CentOS6 の場合】
# /etc/rc.d/init.d/sendmail stop
# chkconfig sendmail off
設定内容を確認
# chkconfig --list sendmail
sendmail        0:オフ  1:オフ  2:オフ  3:オフ  4:オフ  5:オフ  6:オフ
【Fedora16以降 の場合】
CentOS7 はデフォルトでPostfixとなっている為、不要
# systemctl stop sendmail.service
# systemctl disable sendmail.service
設定内容を確認
# systemctl status sendmail.service
sendmail.service - Sendmail Mail Transport Agent
          Loaded: loaded (/lib/systemd/system/sendmail.service; disabled)
          Active: inactive (dead) since Tue, 15 Nov 2011 09:21:02 +0900; 27min ago
        Main PID: 973 (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/sendmail.service
【共通】
デフォルトMTAの変更
# alternatives --config mta
2 プログラムがあり 'mta' を提供します。
  選択       コマンド
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix
上記一覧の「postfix」側の番号を入力
Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
       | 
    
      OS起動時にpostfixとSMTP-Authを起動する
【FC1 から Fedora15 / CentOS4 / CentOS5 / CentOS6 の場合】
# chkconfig postfix on
# chkconfig saslauthd on
設定内容を確認
# chkconfig --list postfix
postfix         0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ
# chkconfig --list saslauthd
saslauthd       0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ
【Fedora16以降 / CentOS7 の場合】
# systemctl enable postfix.service
# systemctl enable saslauthd.service
設定内容を確認
# systemctl status postfix.service
postfix.service - Postfix Mail Transport Agent
          Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled)
          Active: inactive (dead)
          CGroup: name=systemd:/system/postfix.service
# systemctl status saslauthd.service
saslauthd.service - SASL authentication daemon.
          Loaded: loaded (/usr/lib/systemd/system/saslauthd.service; enabled)
          Active: inactive (dead)
          CGroup: name=systemd:/system/saslauthd.service
       | 
    
      postfiix・SMTP-Authを起動する 【FC1 から Fedora15 / CentOS4 / CentOS5 / CentOS6 の場合】 # /etc/rc.d/init.d/postfix start # /etc/rc.d/init.d/saslauthd start 【Fedora16以降 / CentOS7 の場合】 # systemctl start postfix.service # systemctl start saslauthd.service  | 
    
WANから接続するに当たって、ルータの設定が必要です。
ルータのポート開閉は、ご自分のルータ取扱説明書をご覧ください。
DNS名で接続するには事前にドメイン名の取得を行っている必要があります。(以下は代表的なものであり、また、当サイトが使用させて頂いております)
当サイトで紹介しているpostfixの設定は、SMTP-Auth(送信認証)を使用する様に設定しています。
クライアントのメールソフトがSMTP-Auth(送信認証)に対応している必要があります。
主な、SMTP-Auth(送信認証)対応メールソフト
SMTP-Authユーザパスワードを何処に設定するのか?という質問が多々見受けられるので「Becky!」を例にあげて説明します。
メールボックスの設定で「詳細」タブを開き、SMTP認証グループ内の以下の項目を指定します。

チェックボックスはデフォルトのままでも構いませんが、「CRAM-MD5」はチェックしておかないとエラーとなります。
一般的にシステムに関するワーニングやアラート等は、Linux自身が管理者(root)へメールを自動的に送っています。
この情報を取得するには、管理者でログインして「# mail」コマンドで確認するか、rootアカウントでクライアントメーラソフト等で取得しなければなりません。
管理者(root)への接続はセキュリティ上、あまり良くありません。そこで、管理者へメールが送られた時、一般ユーザに転送(正確には移動)させる方法を紹介します。
      aliasファイルの変更
# vi /etc/aliases
#
#  Aliases in this file will NOT be expanded in the header from
#  Mail, but WILL be visible over networks or from /bin/mail.
#
#       >>>>>>>>>>      The program "newaliases" must be run after
#       >> NOTE >>      this file is updated for any changes to
#       >>>>>>>>>>      show through to sendmail.
#
# Basic system aliases -- these MUST be present.
mailer-daemon:  postmaster
postmaster:     root
# General redirections for pseudo accounts.
bin:            root
daemon:         root
        :
        :
        :
# Person who should get root's mail
#root:          marc
root宛てをlinuxに変更
root:           linux
変更を反映
# newaliases
       |