カスタム検索
tomo.gif (1144 ツバツイツト)line.gif (927 ツバツイツト)line.gif (927 ツバツイツト)line.gif (927 ツバツイツト)To previous pageTo home pageMailing to me

PostfixでSMTPサーバを立てる
(CentOS3.5)

Modified: 1 August 2005


Postfixの基本設定
動作テストする - 試行錯誤の実験記録


 Postfixの基本設定 

Postfixのパッケージ

RedhatLinuxは、Postfixを薦めていますので、サーバインストールすれば、Postfixはインストールされています。

しかし、同時に、"sendmail"もインストールされているので、その影響が出ますので、アンインストールしておきます。

# rpm -q sendmail
sendmail-8.12.11-4.RHEL3.1
# rpm -e sendmail
警告: /var/log/mail/statistics saved as /var/log/mail/statistics.rpmsave


"/etc/postfix/main.cf"の基本設定

最低限、以下のように変更します。(変更箇所は、赤い色を付けています。)

最低限、以下の5つを指定します。
myhostname, mydomain, myorigin, inet_interfaces, mynetworks

# Global Postfix configuration file. This file lists only a subset
# of all 100+ parameters. See the sample-xxx.cf files for a full list.
#
# The general format is lines with parameter = value pairs. Lines
# that begin with whitespace continue the previous line. A value can
# contain references to other $names or ${name}s.
#
# NOTE - CHANGE NO MORE THAN 2-3 PARAMETERS AT A TIME, AND TEST IF
# POSTFIX STILL WORKS AFTER EVERY CHANGE.

   :
   :
   :

# 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.tomo.ac

# 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 = tomo.ac

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

   :
   :
   :

# 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. Continue long lines by starting the
# next line with whitespace.
#
mydestination = $myhostname, localhost.$mydomain, $mydomain
#mydestination = $myhostname, localhost.$mydomain, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain

   :
   :
   :

# 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 = 168.100.189.0/28, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
mynetworks = 192.168.0.0/24, 127.0.0.0/8

   :
   :
   :

# readme_directory: The location of the Postfix README files.
#
readme_directory = /etc/postfix/README_FILES
alias_database = hash:/etc/postfix/aliases

"inet_interfaces = all"を指定しないと、postfixをインストールしているPCしか利用できません。つまり、他のPCから利用できません。
(つまり、"inet_interfaces = all"を指定しないと、ポート25が開きません。)

以下のコマンドで設定の確認をします。

# postfix check
#

何も出ず、プロンプトが帰ってきたら設定はOKです。


起動する

以下のコマンドで起動します。

# service postfix start

なお、自動起動は、以下の設定で可能になります。

# chkconfig postfix on

以下のプロセスが起動しておればOKです。

      :
 903 ? S 0:00 /usr/libexec/postfix/master
 906 ? S 0:00 pickup -l -t fifo -u -c
 907 ? S 0:00 nqmgr -l -n qmgr -t fifo -u -c
      :

また、ログは、以下のようにエラーが出ていなければOKです。

      :
 Nov 23 19:42:44 rh73-93-mail-postfix postfix/master[4575]: daemon started

 動作テストする 

試行錯誤を繰り返して、実験した記録です。

自身のホストからメールを出してみる

以下のコマンドで、メールを出して見ます。

# mail tomo@test.com

届いたメールのヘッダーを見ると、以下のように、差出人のドメイン名が変です。

From: root <root@localhost.localdomain>
Message-Id: <200507310032.j6V0WbKb007677@localhost.localdomain>
To: tomo@test.com
Subject: test1

これは、"/etc/hosts"の設定の問題です。

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               dsetcmail localhost.localdomain localhost

インストール後、"/etc/hosts"の内容は上記のようになっていますので、以下のように変更してみます。

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost

再度メールを出してみると、以下のように、差出人のドメインが正しくなりました。

From: root <root@mail.tomo.ac>
Message-Id: <200507310043.j6V0hJVo007690@mail>
To: queen@co-recipe.com
Subject: test2

ログを見てみる "status=sent" が見えれば成功です。もちろん、送信先に届いていることの最終確認が必要です。

Jul 31 10:37:11 dsetcmail postfix/pickup[7618]: D19493313F: uid=0 from=<root>
Jul 31 10:37:11 dsetcmail postfix/cleanup[7871]: D19493313F: 
                    message-id=<20050731013711.D19493313F@dsetcmail.tomo.ac>
Jul 31 10:37:11 dsetcmail postfix/nqmgr[1035]: D19493313F: 
                    from=<root@tomo.ac>, size=287, nrcpt=1 (queue active)
Jul 31 10:37:42 dsetcmail postfix/smtp[7873]: D19493313F: 
                    to=<tomo@cccc.com>, relay=cla.cccc.com[111.222.33.44], delay=31, 
                    status=sent (250 KAA29085 Message accepted for delivery)


外部からメールを出してみる

yahooなどのメールアカウントで、自分のメールサーバーにメールを出して見ます。

外部からメールを受け取るには、DNSのMXレコードがきちんと設定されていないとだめです。受け取れない場合は確認しましょう。

$TTL    3D
tomo.ac. IN SOA mail.tomo.ac. info.mail.tomo.ac. (
                        2005073101      ; serial
                        28800           ; refresh
                        14400           ; retry
                        3600000         ; expiry
                        38400 )         ; minimum

tomo.ac.                IN NS           mail.tomo.ac.
tomo.ac.                IN NS           ns2.eonet.ne.jp.

tomo.ac.                IN MX 10        mail.tomo.ac.

tomo.ac.                IN A            111.222.33.44
mail.tomo.ac.           IN A            111.222.33.44

受け取ったときのログを見てみます。

Jul 31 16:15:01 dsetcmail postfix/smtpd[9772]: connect from web2914.mail.bbt.yahoo.co.jp[202.93.81.92]
Jul 31 16:15:01 dsetcmail postfix/smtpd[9772]: B642A33A6D: client=web2914.mail.bbt.yahoo.co.jp[202.93.81.92]
Jul 31 16:15:01 dsetcmail postfix/smtpd[9772]: warning: the "check_relay_domains" restriction is going away; use "reject_unauth_destination" instead
Jul 31 16:15:01 dsetcmail postfix/smtpd[9772]: warning: restriction `reject' after `check_relay_domains' is ignored
Jul 31 16:15:01 dsetcmail postfix/cleanup[9773]: B642A33A6D: message-id=<20050731071437.91817.qmail@web2914.mail.bbt.yahoo.co.jp>
Jul 31 16:15:01 dsetcmail postfix/nqmgr[9681]: B642A33A6D: from=<tomoac@yahoo.co.jp>, size=1093, nrcpt=1 (queue active)
Jul 31 16:15:01 dsetcmail postfix/smtpd[9772]: disconnect from web2914.mail.bbt.yahoo.co.jp[202.93.81.92]
Jul 31 16:15:01 dsetcmail postfix/local[9774]: B642A33A6D: to=<tomo@tomo.ac>, relay=local, delay=0, status=sent (mailbox)

To previous pageTo home pageMailing to meJump to Top of pageline.gif (927 ツバツイツト)line.gif (927 ツバツイツト)tomo.gif (1144 ツバツイツト)
カスタム検索


Tweet