さくらのVPS導入手順 10.postfixの利用準備

さくらのVPSのお試し期間のメール送信制限

さくらのVPSには2週間のお試し期間があるので、それを利用されている方が多いと思いますが、その間はいくつかの制限事項があります
その中のひとつに、外向きメール送信用のポート番号25が閉じた状態であるということがあります
よって、その期間内はメール送信ができません
なお、受信だけはできますので、メールマガジンなどを受け取るだけなら特に問題なく使用できます
お試し期間が終了するか、途中で自ら本登録すると、その数日後にお知らせ番号が郵送されてくるので、それを入力すればすべての機能が利用できるようになります

メールサーバーの構築方針

ここでは、最も簡単に、標準で動作しているpostfixにdovecotを組み合わせ、スタンダードなSMTP認証で送信時認証を行なう形式で設置します
さらにセキュリティを高めた設置方法についてはまた改めて記載します

postfixのインストール

さくらのVPSでは初期状態でpostfixがインストールされています
よって、インストール作業は必要ありません

postfix設定ファイルの編集

では、こちらも同じようにまずは設定ファイルのバックアップを取った後で編集を行います

$ sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.original
$ sudo 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 = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.talisnet.info (←あなたのメールサーバー用のホスト名に変更)

# 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 = domain.tld
mydomain = talisnet.info (←あなたのメールのドメイン名に変更)

次に、myorigininet_interfacesの項で、15行目と29行目のコメントマークをはずし、32行目を逆にコメントにします
なお、ここまでに説明はしていませんが、IPv6を無効にする方は35~36行目の修正を入れておくとログにIPv6関連の警告が出なくなります

# 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 = $myhostname
myorigin = $mydomain

# RECEIVING MAIL

# 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
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
#inet_protocols = all
inet_protocols = ipv4

次に32行目と33行目のコメントを入れ替える

# 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
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

次はhome_mailboxの項について、下の9行目のコメントを解除します

# 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 = Mailbox
home_mailbox = Maildir/

次はsmtpd_bannerの項について、12行目の内容を追加します

# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown

最後に、設定ファイルの末尾に以下の内容をすべて追記します

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

SMTP-Auth設定ファイルの編集

もうひとつ、メール送信時の認証用サービスがありますので、そちらの設定ファイルも編集します
こちらも同じようにまずは設定ファイルのバックアップを取った後で編集を行います

$ sudo cp /etc/sasl2/smtpd.conf /etc/sasl2/smtpd.conf.original
$ sudo vi /etc/sasl2/smtpd.conf

ここでは認証用のユーザー名とパスワードをシステムとは別々にする形を想定します
1行目の内容を3行目の形に書き換えてください

pwcheck_method: saslauthd
  ↓ 変更
pwcheck_method: auxprop
mech_list: plain login

新規ユーザー用メールボックス作成

新規ユーザ作成時に自動でホームディレクトリにMaildir形式のメールボックスが作成されるようにしておきます

$ sudo mkdir -p /etc/skel/Maildir/{new,cur,tmp}
$ sudo chmod -R 700 /etc/skel/Maildir/

サービスの起動と登録

では、postfixとsaslauthを起動し、自動起動の登録をしておきましょう
まずはsaslauthdからです
1行目で起動し、3行目のコマンドで自動起動登録、4行目でその確認です

$ sudo service saslauthd start
saslauthd を起動中:                                        [  OK  ]
$ sudo chkconfig saslauthd on
$ chkconfig --list saslauthd
saslauthd       0:off   1:off   2:on    3:on    4:on    5:on    6:off

次にpostfixです
こちらは初期状態で起動していて、また自動起動設定も行なわれているはずなので、1行目で再起動を行い、4行目で自動起動の確認を行ないます

$ sudo service postfix restart
postfix を停止中:                                          [  OK  ]
postfix を起動中:                                          [  OK  ]
$ chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

ここまでで、メール送信用サーバーの設定は完了しましたが、メールの受信用サーバーが設置できていません
というわけで、続きは次の記事で

次は さくらのVPS導入手順 11.dovecotの利用準備

はじめに戻る さくらのVPS導入手順 0.はじめに

↓↓↓ブログランキングに参加しています↓↓↓

にほんブログ村 IT技術ブログへ

↑↑↑応援よろしくお願いします↑↑↑

■ AD ■

コメントを残す

メールアドレスが公開されることはありません。