ブログシステム - BLOG.BBTUNE.COM -

Postfix

[Postfix]受信・送信メールの最大サイズ

# main.cf
# size (1024*1024 1M)
message_size_limit = 1048576

この一行を追加して、1メガ以上のメールを受け付けないようにします。
2007-07-11 21:57:05

[Postfix/PHP] 受信メールをPHPへ渡す。

# -------------------------------------------------
# /etc/aliases

phpwork: "| /usr/local/bin/php -f /home/mail/test.php > /tmp/mail"

phpwork に来たら、パイプでphpにデータを渡す。

# -------------------------------------------------
# test.php

受信データをvar_dumpで出力

<?
$in = file_get_contents("php://stdin");
var_dump($in);
?>


# -------------------------------------------------
# 外から送信してみる。

# telnet xxxx 25
Trying xxxxx...
Connected to xxx (xxxx).
Escape character is '^]'.
220 xxxx ESMTP Postfix
MAIL FROM: xxx
250 Ok
RCPT TO: phpwork
250 Ok
DATA
354 End data with .
To: work
Subject: Title
bodyda
.
250 Ok: queued as 40BE03C402B

# -------------------------------------------------
# /tmp/mailは?

string(462) "From xxxx Wed Jul 11 02:34:13 2007
Return-Path:
X-Original-To: phpwork
Delivered-To: phpwork@xxxxx
Received: from unknown (unknown [xxxx])
by xxx (Postfix) with SMTP id 40BE03C402B
for ; Wed, 11 Jul 2007 02:33:28 +0900 (JST)
To: phpwork@
Subject: Title
Message-Id: <20070710173328.40BE03C402B@xxxx>
Date: Wed, 11 Jul 2007 02:33:28 +0900 (JST)

bodyda

# -------------------------------------------------

こんな感じでOKでした。
次はメールを解析しないと。
2007-07-11 02:41:18

[Postfix]エイリアスで外部アドレスに転送。

# -------------------------------------------------
# main.cf
#ローカルからは送信可能にして、ドメインをチェック。
smtpd_recipient_restrictions = permit_mynetworks,
check_relay_domains

# エイリアスの設定
alias_maps = hash:/etc/aliases

初期設定では、UNIXユーザかaliasesに入っているユーザ名には送信可能

# -------------------------------------------------
# /etc/aliases

asobu: ユーザID@gmail.com

とすると
asobuに来たメールをgmailに送信することが出来る。
permit_mynetworks,でローカルからの送信を可能にしておく必要がある。
2007-07-11 02:18:13

[Postfix]特定の送信先のみ許可する。

自宅のFC3はqmailを動かしていたのでPostfixに変更。

# yum install postfix

postfix-2.1.5-5.i3 が入った。


port25で自分のドメインだけ受ける設定にする。


/etc/postfix/main.cf
の変更部分
------------------------------------
myhostname = ant.as4.org

mydomain = as4.org


mydestination = $myhostname, localhost.$mydomain, localhost

inet_interfaces = all

最後に許可&拒否
mydestination にあるドメインのみ許可。
他は拒否。

smtpd_recipient_restrictions = check_relay_domains,
reject_unauth_destination
------------------------------------

220 ant.as4.org ESMTP Postfix
MAIL FROM: xxxx@xxx.as4.org
250 Ok
RCPT TO: xxxxx@gmail.com
554 : Recipient address rejected: Relay access denied
RCPT TO: xxxxx@xxx.as4.org
554 : Recipient address rejected: Relay access denied
RCPT TO: root@ant.as4.org
250 Ok
DATA
354 End data with .
Subject : test
test
.
250 Ok: queued as 582183C402B
quit
221 Bye

実際に実行してみると。
これでOK

適当なユーザ名も受け付けないのでOK
RCPT TO: kamon
550 : Recipient address rejected: User unknown in local recipient table
exit
502 Error: command not implemented
RCPT TO: kamon@ant.as4.org
550 : Recipient address rejected: User unknown in local reci
pient table
quit
221 Bye
2007-07-10 23:39:24

[Postfix]Postfix で SMTP AUTH

Outbound Port 25 Blockingでport25を使えなくなってしまったので。
とりあえず587 で利用できるようにする。
/etc/postfix/master.cfの submission を有効にする

submission inet n - n - - smtpd

こちらは、まだコメントのまま
# -o smtpd_etrn_restrictions=reject
# -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#


iptables も 587 を利用可能にしておく。

これで、外部から
telnet xxx.xxx.org 587
で接続できた。

220 xxx.xxx.org ESMTP Postfix
ehlo xxx.xxx.org
250-xxx.xxx.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250 8BITMIME
quit
221 Bye

とOK

次に smtp auth を実装する。

まずは
yum install cyrus-sasl
cyrus-sasl-devel i386 2.1.20-6 updates-released 1.4 M
cyrus-sasl-md5 i386 2.1.20-6 updates-released 58 k
cyrus-sasl-plain i386 2.1.20-6 updates-released 29 k
この3つをインストールしてみた。

/etc/postfix/master.cfの2行のコメントを外す。
-o smtpd_etrn_restrictions=reject
-o smtpd_client_restrictions=permit_sasl_authenticated,reject

そうすると 587 で送信しようとすると
554 <109.105.xxxxxxxx[xxxxxxxxx.105.109]>: Client host rejected: Access denied
とエラーになる。

main.cf に
smtpd_sasl_auth_enable = yes
を追加する!

すると
220 xxx.xxx.org ESMTP Postfix
ehlo xxx.xxx.org
250-xxx.xxx.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN CRAM-MD5 DIGEST-MD5 PLAIN
250 8BITMIME

このようにAUTH LOGINの項目が入る。

sasl用ユーザを作る。

# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
とりあえず、こうしておく。

# vi /etc/sysconfig/saslauthd
Directory in which to place saslauthd's listening socket, pid file, and so
# on. This directory must already exist.
SOCKETDIR=/var/run/saslauthd

# Mechanism to use when checking passwords. Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled to use.
MECH=shadow

デフォルトで
# /etc/shadowを使うので、unix のユーザを作っておく。

testというユーザ名で作成
password もtest として例にする。

# /etc/rc.d/init.d/saslauthd start
# /usr/sbin/testsaslauthd -s smtp -u test -p test
0: OK "Success."
# perl -MMIME::Base64 -e 'print encode_base64("testDETAILtestDETAILtest");'
dGVzdAB0ZXN0AHRlc3Q=

これで確認OK

外からつないでみる!

220 xxx.xxx.org ESMTP Postfix
AUTH PLAIN dGVzdAB0ZXN0AHRlc3Q=
235 Authentication successful

とOK

まだ、Postfixは入れたばかりなので転送許可設定等をもう少し知っておかないと使えないので、ちょっと勉強しておこうと思います。
基本的にiptables でふさいでいるので大丈夫だとは思いますが。
2007-06-16 23:53:28
引越
Google Android
S11HT emonster
windows mobile
silverlight
podcast
apple
ssh
Perl
samba ファイルサーバ
ludia
pound
High Availavility高可用性
pgpool
Google Maps API
Ruby
Postfix
プロバイダー
javascript
PostgreSQL
システム監査
HDD換装
時計
Felica
C#
携帯用サイト作成関連
ネットワーク
XML + XSLT
W-ZERO3 willcom
MySQL
さくらの専用サーバ
ブログ関連
Apache
サーバー管理
情報処理試験
データベース
PHP
Unix-Linux
動画関連メモ
人気商品情報
アマゾン関連
追加機能予定
システムメモ

Postfix 記事一覧
[Postfix]受信・送信メールの最大サイズ
[Postfix/PHP] 受信メールをPHPへ渡す。
[Postfix]エイリアスで外部アドレスに転送。
[Postfix]特定の送信先のみ許可する。
[Postfix]Postfix で SMTP AUTH