7
6

More than 5 years have passed since last update.

ActionMailerの使い方メモ

Last updated at Posted at 2012-09-18

ModelとTemplateの生成

rails g mailer ExampleMailer

文字コードをISO-2022-JPに変更

方法はいくつかあるようだが、どうもさっくり出来る方法が少なそう。
調べた限りだと現状ActionMailerの代わりにjpmobile::mailerを使うのが良さそう。jpmobileに書き換えるとデフォルトはISO-2022-jp、docomo/SoftBankにはShift_JISで送信を行なってくれるらしい。手順は以下

jpmobileを追加インストール

Gemfile
gem 'jpmobile'

ActionMaierの代わりにJpmobile::Mailerを継承する

app/mailers/example_mailer.rb
class ExampleMailer < ActionMailer::Base
   書き換え 
class ExampleMailer < Jpmobile::Mailer::Base

htmlメール textメールの切り替え

単純にViewテンプレートの拡張子によってtext or htmlメールで送るかを決定している様子

template.text.erb # => textメールで送信
template.html.erb # => htmlメールで送信
template.erb      # => htmlメールで送信
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6