複数アプリを動かしている場合、アプリ毎にメールアドレスが欲しくなることがあります。
今回は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パラメータで使う名前を設定します。
shell>>

cat /etc/mailname

a.s21g.com
<<--

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

cat /etc/aliases

postmaster: root

#post_at_b: "| cat $1 > /tmp/mail_test.txt" #test用コード
post_at_b: "| /PATH_TO_RUBY/ruby /PATH_TO_RAILS_ROOT/script/runner -e production 'TestMailer.receive(STDIN.read)'"
<<--

###virtual domainの用意
virtual domainに来た場合どうするかを個別を書きます。
shell>>

cat /etc/postfix/virtual

b.s21g.com anything
post@b.s21g.com post_at_b
<<--

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

shell>>
#/etc/postfix/main.cf
mydestination = localhost, localhost.localdomain, localhost, b.s21g.com
myorigin = /etc/mailname
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_maps = hash:/etc/postfix/virtual
<<--

###各設定を反映
shell>>

postalias /etc/aliases

postmap /etc/postfix/virtual

/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 satoko satoko on Tue 13 May 2008 at 16:57 with 0 comments
Contents rssrss
Leading Smart TV App Development Companies | USA | 4 Way Technologies
Apple TV Developer | TVOS Development | USA | 4 Way Technologies
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Value Transformer
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Tags
ActionMailerpostfix
Comments rssrss
瀧内元気 瀧内元気: MacOS版は以下にあります genki/ViMouse 01/16 05:40
KingofSmack KingofSmack: Here also good reads for this mobile application d... 05/10 18:02
Spencer Spencer: You don't have to re-compile it, this version work... 04/08 07:15
staiano staiano: Any chance we can get a recompile for 10.9? 01/10 01:47
dsjf dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これでも出... 01/08 23:23
yoku0825 yoku0825: nkfの方が使いやすいですが、glibcに含まれているiconvの方が 確実にどの環境にも入っている... 06/11 07:03
falsefalse falsefalse: @tiancongxin try using this one https://github.com... 02/14 08:04
瀧内元気 瀧内元気: おお、チェックしてみます。thx! 12/24 05:23
Services from s21g
YOMU Web小説リーダー
Web小説を音声で楽しむ読み上げリーダー
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン