Postfix

インストール

# yum install -y postfix cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5

設定

  • /etc/postfix/main.cf (抜粋)

    myhostname = mail.<ドメイン>
    mydomain = <ドメイン>
    myorigin = $mydomain
    inet_interfaces = all
    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    local_recipient_maps =
    home_mailbox = Maildir/
    luser_relay = unknown_user@localhost
    smtpd_banner = $myhostname ESMTP unknown
    smtpd_tls_cert_file = /etc/letsencrypt/live/<ドメイン>/fullchain.pem
    smtpd_tls_key_file = /etc/letsencrypt/live/<ドメイン>/privkey.pem
    smtp_tls_CApath = /etc/letsencrypt/live/<ドメイン>/cert.pem
    smtpd_sasl_auth_enable = yes
    smtpd_recipient_restrictions =
        permit_mynetworks
        permit_sasl_authenticated
        reject_unauth_destination
    message_size_limit = 10485760
  • /etc/postfix/master.cf (抜粋)

    submission inet n       -       n       -       -       smtpd
      -o smtpd_sasl_auth_enable=yes
  • /etc/aliases (追加)

    unknown_user: /dev/null

ファイアウォール設定

  • CentOS 7
    # firewall-cmd --permanent --add-service=smtp --add-service=smtp-submission --add-service=smtps
    # firewall-cmd --reload
    # firewall-cmd --list-services

設定反映

  • CentOS 7,8
    # newaliases
    # postalias hash:/etc/aliases
    # alternatives --config mta
    (MTAがリストアップされる)
    (`+`が現在有効になっているMTA)
    (postfixの番号を入力して有効なMTAを変更)
    # systemctl enable postfix saslauthd
    # systemctl restart postfix saslauthd
    # systemctl status postfix saslauthd

Dovecot

インストール

# yum install -y dovecot

設定

  • /etc/dovecot/conf.d/10-mail.conf (抜粋)

    mail_location = maildir:~/Maildir
  • /etc/dovecot/conf.d/10-ssl.conf (証明書は Let's Encrypt で取得)

    ssl = required
    ssl_cert = </etc/letsencrypt/live/<ドメイン>/fullchain.pem
    ssl_key = </etc/letsencrypt/live/<ドメイン>/privkey.pem
    ssl_protocols = !SSLv2 !SSLv3
    ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL
  • /etc/dovecot/conf.d/10-logging.conf (抜粋, デバッグ用)

    auth_verbose = yes
    auth_debug = yes

ファイアウォール設定

  • CentOS 7,8
    # firewall-cmd --permanent --add-service=pop3s
    # firewall-cmd --reload
    # firewall-cmd --list-services

サービス設定

  • CentOS 7,8
    # systemctl enable dovecot
    # systemctl restart dovecot
    # systemctl status dovecot

ログファイル

  • /var/log/maillog
  • ログファイルを監視, Ctrl-C で終了
# tail -f /var/log/maillog