suakx devlog

開発ブログのような

1 note &

rails3.0betaでActionMailerを試してみた

前回に引き続きActionMailerを試してみました。ソースはここ

rails g mailer notifier

でapp/mailers/notifier.rb と app/views/notifierができる。(modelsにできないのが新しい)

こんな感じで書いておくと問題なくメールが送れる。
ヘッダーはこんな感じ。

Subject: Password Reset Instructions
Mime-Version: 1.0
Content-Type: text/plain;
charset="utf-8";
Content-Transfer-Encoding: 7bit

問題は:subjectに日本語を入れた場合、

/app/mailers/notifier.rb:8: invalid multibyte char (US-ASCII)

ってなエラーがでて受け付けてくれない。ruby1.9からの特徴。
でnotifier.rbのファイルの頭に、

# -*- coding: utf-8 -*-

を入れておくとヘッダーは

Subject: =?utf-8?Q?=E3=81=82Password_Reset_Instructions?=

にかわって受け付けてくれる。

reset_password_instructions.text.erbに日本語を入れた場合

Non US-ASCII detected and no content-transfer-encoding defined.
Defaulting to 8bit, set your own if this is incorrect.
/usr/lib/ruby/1.9.1/net/protocol.rb:291: warning: regexp match /.../n against to UTF-8 string

こんな感じのお知らせがでて、ヘッダーは

Content-Transfer-Encoding: 8bit

に変ってくれてる。

<%# coding: utf-8 %>

を頭につけようが付けまいが関係ない。 rails3.0でのactionmailerはTMailからMailに変ったのでその辺がその辺の影響かも(ソースはまだ見てない)。日本語メールのエンコードってISO-2022-JPがデフォというのはわかるけど、アプリの国際化を考えると、IE6を無視しよう運動が行われているようにUTF8が使えないメーラーは無視で簡略化する方向でいいのかと思う今日この頃です。とりあえずgmailとdocomoは

Subject: =?utf-8?Q?=E3=81=82Password_Reset_Instructions?=
Mime-Version: 1.0
Content-Type: text/plain;
charset="utf-8";
Content-Transfer-Encoding: 8bit

のヘッダーは理解してくれてます。

  1. waku reblogged this from devlog
  2. devlog posted this