このサイトは、只今WEB業界で活躍中のデザイナー、プログラマーの方々の情報を集めたweb統合情報サイトです。

Archives Details

CentOS7 Postfix

サーバー

2018.06.25

この記事は最終更新日から1年以上が経過しています。

どもです。

先日ドメインを取得したのですが、せっかくなのでそのドメインで メールサーバ環境を構築したくなった んですよね。ということで、今回はその手順をまるっとメモした形になります。

例によって自分用の備忘録も兼ねているので、構築の流れをそのまま追える形で残しておきます。

環境

まずは今回の環境から。バージョンはこちら。

# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)

CentOS7 系での構築となります。

SMTP-Auth の設定

cyrus-sasl のインストール

まずは SMTP 認証まわりのため、cyrus-sasl をインストールします。

# yum install cyrus-sasl

インストールできたら起動して、

# systemctl start saslauthd

自動起動も設定しておきます。

# systemctl enable saslauthd
saslauthd から auxprop に変更

認証方式を auxprop に変更します。設定ファイルを開いて、

# vim /etc/sasl2/smtpd.conf

以下のように記述します。

pwcheck_method: auxprop
mech_list: plain login

Postfix のインストールと設定

インストール

続いて本命の Postfix をインストール。

yum install postfix
main.cf の編集

設定ファイル /etc/postfix/main.cf を編集していきます。

# vim /etc/postfix/main.cf

ここからは項目ごとに見ていきます。

受信メールサイズの上限設定

今回は 5MB にしておきます。

message_size_limit = 5242880

外部からのメールを許可する

inet_interfaceslocalhost から all に変更します。

# 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

myhostname に自ドメインを設定

mail. の後ろに自分のドメインを追加します。

# 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 = mail.sample.com

mydomain に自ドメインを追加

# 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 = sample.com

myorigin の追加

# 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

mydestination に自ドメインを追加

自分のドメイン宛てのメールを受信できるように変更します。

変更前と変更後はこんな感じ。

変更前: mydestination = myhostname,localhost.myhostname,localhost.mydomain, localhost
変更後: mydestination = myhostname,localhost.myhostname,localhost.mydomain, localhost, $mydomain

実際の設定箇所はこちら。

# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain.  On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

メールボックス形式の追加

Maildir 形式を使うので、home_mailbox を追加します。

# 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-Auth 設定の追加

最後に SMTP-Auth まわりの設定を追加します。

smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
Postfix の起動

設定が終わったら起動(再起動)します。

# systemctl restart postfix

自動起動も設定。

# systemctl enable postfix

Dovecot のインストールと設定

受信側として Dovecot も入れていきます。

インストール
# yum install dovecot
10-mail.conf の編集

メールボックス形式を設定します。

# vim /etc/dovecot/conf.d/10-mail.conf

mail_location に Maildir を指定します。

# Location for users' mailboxes. The default is empty, which means that Dovecot
# tries to find the mailboxes automatically. This won't work if the user
# doesn't yet have any mail, so you should explicitly tell Dovecot the full
# location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# kept. This is called the "root mail directory", and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
#   %u - username
#   %n - user part in user@domain, same as %u if there's no domain
#   %d - domain part in user@domain, empty if there's no domain
#   %h - home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
#   mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
#mail_location =
mail_location = maildir:~/Maildir
10-auth.conf の編集

プレインテキスト認証を有効にします。

# vim /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_authno に変更。

# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
# See also ssl=required setting.
#disable_plaintext_auth = yes
disable_plaintext_auth = no
10-ssl.conf の編集

今回は SSL 接続を無効化します。

# vim /etc/dovecot/conf.d/10-ssl.conf

sslno に変更。

# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
#ssl = required
ssl = no
Dovecot の起動

起動して、

# systemctl start dovecot

自動起動も設定しておきます。

# systemctl enable dovecot

メールユーザの追加

admin ユーザの追加

メール用のユーザを追加します。ログインシェルは無効にしておきます。

# useradd -s /sbin/nologin admin
パスワード変更
# passwd admin
ユーザー admin のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。
Auth 用ユーザ設定

saslpasswd2 で認証用ユーザを登録します。

# echo "[パスワード]" | saslpasswd2 -p -u linux.sample.com -c admin

反映を確認。

# sasldblistusers2
admin@linux.sample.com: userPassword
権限変更

sasldb2 のグループを postfix に変更しておきます。

# chgrp postfix /etc/sasldb2

疎通確認

これで完了です!

あとは、使っているメールソフトに設定を入れて疎通を確認してみます。設定例はこんな感じ。

メールアドレス: admin@sample.com
パスワード: [設定したパスワード]
アカウントの種類: POP
受信用メールサーバ: mail.sample.com
送信用メールサーバ: mail.sample.com

ここまでくれば、自前ドメインでのメールの送受信ができるようになっているはずです。取得したドメインで動くメールサーバが手元にあると、なんだかんだ便利ですし胸アツですね。

ではではぁ。

またまたぁ。

Comment

Related Article

【Railway】ひたすら安く個人開発サービスを運用する計画

2026.04.06

CentOS7 Postfix

2018.06.25

iPhoneXで、ubuntuを動かす。

2018.06.09

CentOS7 nginx

2018.06.02

CATEGORY LIST

LATEST NEWS

ラズパイが高騰しているのでストレス解消のためAliExpressで購入した電子パーツ達

電子工作

2026.08.02

【2026】【VMware Fusion】MacでWindowsを無料で扱う。

windows

2026.07.19

Raspberry Pi 5 でマインクラフトサーバーを立てる(Java版 × 統合版クロスプレイ対応)

RaspberryPi

2026.06.24

ラズパイが高い。

RaspberryPi

2026.05.26

【Claude Code】フル稼働。ToDo Appを様々なGUIフレームワーク用いて作らせる。

AI・Bot・algorithm

2026.05.24

Macで歩く「たのしいバイナリの歩き方」うさみみハリケーンの代わりに、Cheat Engine / Bit slicerを使用する

アセンブラ

2026.04.12

Macで歩く「たのしいバイナリの歩き方」

アセンブラ

2026.04.10

【Railway】ひたすら安く個人開発サービスを運用する計画

サーバー

2026.04.06

たびのきろく

イベント

2026.02.23

【Railway】MySQLサービスをコスト抑えて運用する

運用

2026.01.19

あけましておめでとうございますmm DjangoアプリをRailwayに移行する。

運用

2026.01.06

効率の良い AI駆動開発について考える

AI・Bot・algorithm

2025.11.09

RANKING

Follow

SPONSOR

現在、掲載募集中です。



Links

About Us

WEBデザイナーの、WEBデザイナーによる、WEBデザイナーの為のサイト。「みんなで書こう!」と仲間を募ってみたが、結局書くのは自分だけとなってしまいました。日々のメモを綴っていきます。

Entry Profile

Graphical FrontEnd Engineer
- Daisuke Takayama

MAD CITY 北九州市で生まれ育つ。20代はバンド活動に明け暮れ、ふと「webデザイナーになりたい。」と思い、デジタルハリウッド福岡校入学。卒業後、数々の賞を受賞、web業界をざわつかせる。
現在、主に、ゲーム制作中心に港区六本木界隈で活動中。

FOLLOW US