• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

複数アプリを動かしている場合、アプリ毎にメールアドレスが欲しくなることがあります。
今回はpostfixのvirtual domain、virtual aliasを使って実現しました。1つのサーバ(host名:x.s21g.com)で、a.s21g.com, b.s21g.comのメール受信ができるようになります。流れとしては、

  1. satoko@b.s21g.comで受信したメールを
  2. satoko_at_b@a.s21g.comに転送
  3. それをscript/runncerで処理ということになります。

mailnameの用意

myoriginパラメータで使う名前を設定します。

   1  # cat /etc/mailname
   2  a.s21g.com

virtual aliasesの用意

メール受信時どういう処理をするかです: railsの場合script/runnerに食わせます。
PATHはそれぞれ書き換えてください。

   1  # cat /etc/aliases
   2  postmaster:    root
   3  
   4  #post_at_b: "| cat $1 > /tmp/mail_test.txt" #test用コード
   5  post_at_b: "| /PATH_TO_RUBY/ruby /PATH_TO_RAILS_ROOT/script/runner -e production 'TestMailer.receive(STDIN.read)'"

virtual domainの用意

virtual domainに来た場合どうするかを個別を書きます。

   1  # cat /etc/postfix/virtual
   2  b.s21g.com         anything
   3  post@b.s21g.com post_at_b

postfixの設定を変更

mydestinationにb.s21g.comを設定、myorigin, virtual alias、virtual domainも指定します。

   1  #/etc/postfix/main.cf
   2  mydestination = localhost, localhost.localdomain, localhost, b.s21g.com
   3  myorigin = /etc/mailname
   4  alias_maps = hash:/etc/aliases
   5  alias_database = hash:/etc/aliases
   6  virtual_alias_maps = hash:/etc/postfix/virtual 

各設定を反映

   1  # postalias /etc/aliases
   2  # postmap /etc/postfix/virtual
   3  # /etc/rc.d/init.d/postfix restart

(注意) a.s21g.comはDNSに登録してください。メール送信時、インターネット上でDNSが牽ける名前か相手サーバからチェックされており、その時点で蹴られてしまうからです。
(注意) スパムに使われないようにリレーを設定します:main.cf
relayhost =
mynetworks = 127.0.0.0/8

Refs

http://blog.s21g.com/articles/569
http://www.tmtm.org/postfix/tutorial/index.html
http://furukawa.blogdns.com/furukawa/2006/04/postfix.html
http://www.jitaku-server.net/postfix_virtual_domain.html

posted by Png satoko on Tue 13 May 2008 at 16:50
Contents
postfixでrailsアプリごとにメールアドレスを持つ:virtual domain, virtual alias
Comments
KingofSmack: Here also good reads for this mobile applicatio... '14-5
satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよっ... '10-12
ujihisa: :%s/blog/glob/g '10-7
satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 ... '09-10
しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫... '09-10
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ