Mac OS X と pkgsrc で Postfix Mac OS X にはあらかじめ Postfix がインストールされているがせっかくだから pkgsrc してみる。 !! 参考 Postfix のページ http://www.kobitosan.net/postfix/ ひっきー - Postfix(with SMTP-AUTH) http://nekojita.org/hiki/Postfix.html Postfix で Maildir 配送をする http://www.ftserve.net/~fuji/linux/maildir.shtml !!インストール pkgsrc を使う。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo bmake install clearn ←じつは clean を typo してる ===> Extracting for postfix-2.2.5 ========================================================================== The supported build options for this package are: bdb ldap mysql mysql4 pcre pgsql sasl tls You can select which build options to use by setting PKG_DEFAULT_OPTIONS or the following variable. Its current value is shown: PKG_OPTIONS.postfix (not defined) Deprecated variable USE_OPENLDAP used, use PKG_DEFAULT_OPTIONS+=ldap instead. ========================================================================== ========================================================================== The following variables will affect the build process of this package, postfix-2.2.5. Their current value is shown below: * BDBBASE (defined) * BDB_TYPE = db1 You may want to abort the process now with CTRL-C and change their value before continuing. Be sure to run `/usr/pkg/bin/bmake clean' after the changes. ========================================================================== ===> Required installed package user>=20040801: user-20040801 found ===> Patching for postfix-2.2.5 ===> Applying pkgsrc patches for postfix-2.2.5 ===> Overriding tools for postfix-2.2.5 ===> Creating toolchain wrappers for postfix-2.2.5 ===> Configuring for postfix-2.2.5 ===> Building for postfix-2.2.5 ===> Creating /Volumes/NetBSD/pkgsrc/mail/postfix/work/postfix ===> Installing for postfix-2.2.5 Creating group: maildrop /usr/bin/install -d -o root -g wheel -m 755 /Volumes/NetBSD/pkg/libexec/postfix /usr/bin/install -d -o root -g wheel -m 755 /Volumes/NetBSD/pkg/share/examples/postfix /usr/bin/install -d -o root -g wheel -m 755 /Volumes/NetBSD/pkg/share/doc/postfix /bin/rm -f /Volumes/NetBSD/pkgsrc/mail/postfix/work/postfix-2.2.5/conf/*.orig /usr/bin/install -c -o root -g wheel -m 555 /Volumes/NetBSD/pkgsrc/mail/postfix/work/postfix-2.2.5/conf/post-install /Volumes/NetBSD/pkg/share/examples/postfix /usr/bin/install -c -o root -g wheel -m 555 /Volumes/NetBSD/pkgsrc/mail/postfix/work/postfix-2.2.5/conf/postfix-script /Volumes/NetBSD/pkg/share/examples/postfix /usr/bin/install -c -o root -g wheel -m 444 /Volumes/NetBSD/pkgsrc/mail/postfix/work/mailer.conf /Volumes/NetBSD/pkg/share/examples/postfix/mailer.conf : =========================================================================== Installing files needed by postfix-2.2.5: /Volumes/NetBSD/pkg/etc/postfix/main.cf [/Volumes/NetBSD/pkg/share/examples/postfix/main.cf] /Volumes/NetBSD/pkg/etc/postfix/master.cf [/Volumes/NetBSD/pkg/share/examples/postfix/master.cf] /Volumes/NetBSD/pkg/etc/postfix/post-install [/Volumes/NetBSD/pkg/share/examples/postfix/post-install] /Volumes/NetBSD/pkg/etc/postfix/postfix-files [/Volumes/NetBSD/pkg/share/examples/postfix/postfix-files] /Volumes/NetBSD/pkg/etc/postfix/postfix-script [/Volumes/NetBSD/pkg/share/examples/postfix/postfix-script] =========================================================================== =========================================================================== The following files should be created for postfix-2.2.5: /etc/rc.d/postfix (m=0755) [/Volumes/NetBSD/pkg/share/examples/rc.d/postfix] =========================================================================== ===> Please note the following: =========================================================================== $NetBSD: MESSAGE,v 1.8 2004/07/19 22:03:13 jlam Exp $ Please run the following command to update main.cf and master.cf with the latest Postfix services and configuration directives: /Volumes/NetBSD/pkg/sbin/postfix upgrade-configuration If you are upgrading from a previous Postfix installation, you may want to back up any existing configuration files before running the above command. Postfix may be activated by executing: /Volumes/NetBSD/pkg/sbin/postfix start =========================================================================== ===> Registering installation for postfix-2.2.5 postfix-2.2.5 requires installed package user-20040801 bmake: don't know how to make clearn. Stop bmake: stopped in /usr/pkgsrc/mail/postfix rin@kahori[/usr/pkgsrc/mail/postfix]% sudo bmake clean ===> Cleaning for postfix-2.2.5 rin@kahori[/usr/pkgsrc/mail/postfix]% !! pre postfix あらかじめインストールされている postfix たちを削除する。 こっちが pre インストール。 rin@kahori[/usr/pkgsrc/mail/postfix]% ls /usr/sbin/post* /usr/sbin/postalias* /usr/sbin/postkick* /usr/sbin/postcat* /usr/sbin/postlock* /usr/sbin/postconf* /usr/sbin/postlog* /usr/sbin/postdrop* /usr/sbin/postmap* /usr/sbin/postfix* /usr/sbin/postqueue* /usr/sbin/postfix-watch* /usr/sbin/postsuper* こっちが pkg 。 rin@kahori[/usr/pkgsrc/mail/postfix]% ls /usr/pkg/sbin/post* /usr/pkg/sbin/postalias* /usr/pkg/sbin/postlock* /usr/pkg/sbin/postcat* /usr/pkg/sbin/postlog* /usr/pkg/sbin/postconf* /usr/pkg/sbin/postmap* /usr/pkg/sbin/postdrop* /usr/pkg/sbin/postqueue* /usr/pkg/sbin/postfix* /usr/pkg/sbin/postsuper* /usr/pkg/sbin/postkick* 削除。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo rm /usr/sbin/post* !! 設定ファイル main.cf と aliases を設定する。 main.cf はこう。 Maildir を使うために home_mailbox = Maildir/ している。 rin@kahori[/usr/pkgsrc/mail/postfix]% diff -u /usr/pkg/share/examples/postfix/main.cf /usr/pkg/etc/postfix/main.cf --- /usr/pkg/share/examples/postfix/main.cf Tue Aug 9 15:51:30 2005 +++ /usr/pkg/etc/postfix/main.cf Tue Aug 9 16:19:54 2005 @@ -65,7 +65,7 @@ # from gethostname(). $myhostname is used as a default value for many # other configuration parameters. # -#myhostname = host.domain.tld +myhostname = sakura.area51.gr.jp #myhostname = virtual.domain.tld # The mydomain parameter specifies the local internet domain name. @@ -73,7 +73,7 @@ # $mydomain is used as a default value for many other configuration # parameters. # -#mydomain = domain.tld +mydomain = area51.gr.jp # SENDING MAIL # @@ -89,7 +89,7 @@ # to recipient addresses that have no @domain part. # #myorigin = $myhostname -#myorigin = $mydomain +myorigin = $mydomain # RECEIVING MAIL @@ -151,7 +151,7 @@ # 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 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, # mail.$mydomain, www.$mydomain, ftp.$mydomain @@ -250,7 +250,7 @@ # 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 = 168.100.0.0/24, 127.0.0.0/8 #mynetworks = $config_directory/mynetworks #mynetworks = hash:/etc/postfix/network_table @@ -372,7 +372,7 @@ # "postfix reload" to eliminate the delay. # #alias_maps = dbm:/etc/aliases -#alias_maps = hash:/etc/aliases +alias_maps = hash:/etc/aliases #alias_maps = hash:/etc/aliases, nis:mail.aliases #alias_maps = netinfo:/aliases @@ -383,7 +383,7 @@ # #alias_database = dbm:/etc/aliases #alias_database = dbm:/etc/mail/aliases -#alias_database = hash:/etc/aliases +alias_database = hash:/etc/aliases #alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases # ADDRESS EXTENSIONS (e.g., user+foo) @@ -405,7 +405,7 @@ # "Maildir/" for qmail-style delivery (the / is required). # #home_mailbox = Mailbox -#home_mailbox = Maildir/ +home_mailbox = Maildir/ # The mail_spool_directory parameter specifies the directory where # UNIX-style mailboxes are kept. The default setting depends on the /etc/aliases はこう。 rin@kahori[/usr/pkgsrc/mail/postfix]% cat /etc/aliases MAILER-DAEMON: postmaster webmaster: root postmaster: root postfix: root root: rin aliases を作成。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo newaliases 設定を確認。 warning をいわれるけど無視。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo postfix check postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/public postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/maildrop !! 起動 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo postfix start postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/public postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/maildrop postfix/postfix-script: starting the Postfix mail system ひとまずメッセージによれば起動したっぽい。 見てみる。 rin@kahori[/usr/pkgsrc/mail/postfix]% ps waux | grep postfix プロセスがない。 netstat してみる。 rin@kahori[/usr/pkgsrc/mail/postfix]% netstat -na | grep LISTEN tcp4 0 0 *.110 *.* LISTEN tcp4 0 0 *.25 *.* LISTEN すでに qmail が起動していたことを忘れていた。 qmail を停止する。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo svc -d /service/qmail rin@kahori[/usr/pkgsrc/mail/postfix]% sudo svc -d /service/smtpd/ rin@kahori[/usr/pkgsrc/mail/postfix]% sudo svc -d /service/pop3d/ rin@kahori[/usr/pkgsrc/mail/postfix]% sudo rm /service/qmail rin@kahori[/usr/pkgsrc/mail/postfix]% sudo rm /service/smtpd rin@kahori[/usr/pkgsrc/mail/postfix]% sudo rm /service/pop3d もう一度 postfix を起動。 rin@kahori[/usr/pkgsrc/mail/postfix]% sudo postfix start sudo postfix start postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/public postfix/postfix-script: warning: not owned by group maildrop: /var/spool/postfix/maildrop postfix/postfix-script: starting the Postfix mail system netstat してみる。 rin@kahori[/usr/pkgsrc/mail/postfix]% netstat -na | grep LISTEN tcp4 0 0 *.25 *.* LISTEN postfix は SMTP 専用なので 25 番のみ。 プロセスを見てみる。 rin@kahori[/usr/pkgsrc/mail/postfix]% ps auxw | grep postfix ps auxw | grep postfix root 11229 0.0 0.2 18180 464 ?? Ss 4:46PM 0:00.03 /Volumes/NetBSD/pkg/libexec/postfix/master postfix 11230 0.0 0.4 18200 1004 ?? S 4:46PM 0:00.00 pickup -l -t fifo -u postfix 11231 0.0 0.4 18252 1040 ?? S 4:46PM 0:00.01 qmgr -l -t fifo -u rin@kahori[/usr/pkgsrc/mail/postfix]% !! 動作確認 ローカルからローカルへ。 SMTP をしゃべる。 rin@kahori[~]% telnet 127.0.0.1 25 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 sakura.area51.gr.jp ESMTP Postfix HELO area51.gr.jp 250 sakura.area51.gr.jp mail from: 250 Ok rcpt to: 250 Ok data 354 End data with . Subject: test2 test2 . 250 Ok: queued as 5AD39172050 quit 221 Bye Connection closed by foreign host. ログ。 Aug 10 11:29:54 kahori postfix/smtpd[12901]: connect from localhost[127.0.0.1] Aug 10 11:30:31 kahori postfix/smtpd[12901]: 5AD39172050: client=localhost[127.0 .0.1] Aug 10 11:30:41 kahori postfix/cleanup[12911]: 5AD39172050: message-id=<20050810 023023.5AD39172050@sakura.area51.gr.jp> Aug 10 11:30:42 kahori postfix/qmgr[11231]: 5AD39172050: from= , size=365, nrcpt=1 (queue active) Aug 10 11:30:42 kahori postfix/local[12912]: 5AD39172050: to=, relay=local, delay=19, status=sent (delivered to maildir) Aug 10 11:30:42 kahori postfix/qmgr[11231]: 5AD39172050: removed Aug 10 11:30:43 kahori postfix/smtpd[12901]: disconnect from localhost[127.0.0.1 メール。 ちゃんと Maildir に届いている。 rin@kahori[~]% ls -lR ~/Maildir/ total 0 drwx------ 2 rin rin 68 30 8 12:55:10 2003 cur/ drwx------ 3 rin rin 102 10 8 11:30:42 2005 new/ drwx------ 2 rin rin 68 10 8 11:30:42 2005 tmp/ /Users/rin/Maildir//cur: /Users/rin/Maildir//new: total 8 -rw------- 1 rin rin 449 10 8 11:30:42 2005 1123641042.Ve000002I172051M144763.kahori.local /Users/rin/Maildir//tmp: 内容。 rin@kahori[~/Maildir/new]% cat 1123641042.Ve000002I172051M144763.kahori.local Return-Path: X-Original-To: rin@area51.gr.jp Delivered-To: rin@area51.gr.jp Received: from area51.gr.jp (localhost [127.0.0.1]) by sakura.area51.gr.jp (Postfix) with SMTP id 5AD39172050 for ; Wed, 10 Aug 2005 11:30:23 +0900 (JST) Subject: test2 Message-Id: <20050810023023.5AD39172050@sakura.area51.gr.jp> Date: Wed, 10 Aug 2005 11:30:23 +0900 (JST) From: rin@area51.gr.jp To: undisclosed-recipients:; test2 !! 起動項目 以下のように修正。 rin@kahori[~]% diff -u /System/Library/StartupItems/Postfix/Postfix.src /System/Library/StartupItems/Postfix/Postfix /dev/null } @@ -23,7 +23,7 @@ { if [ "${MAILSERVER:=-NO-}" = "-YES-" ]; then ConsoleMessage "Reloading Postfix configuration" - /usr/sbin/postfix reload + /usr/pkg/bin/postfix reload else StopService fi rin@kahori[~]%