Skip to content

Instantly share code, notes, and snippets.

@tyabe
Created August 9, 2011 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyabe/1133843 to your computer and use it in GitHub Desktop.
Save tyabe/1133843 to your computer and use it in GitHub Desktop.
Railsの config/initializers の下に置いておくメール設定
# coding: utf-8
# Loads action_mailer settings from email.yml
# and turns deliveries on if configuration file is found
filename = File.join(File.dirname(__FILE__), '..', 'email.yml')
if File.file?(filename)
mailconfig = YAML::load_file(filename)
if mailconfig.is_a?(Hash) && mailconfig.has_key?(Rails.env)
mailconfig[Rails.env].each do |k, v|
v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
ActionMailer::Base.send("#{k}=", v)
end
end
end
class ActionMailer::Base
layout 'email'
default :from => "from@example.com",
'Content-Transfer-Encoding' => '7bit'
end
# 文字コード変換絡みのWarningが出ないようにする対策
# .../net/protocol.rb:305: warning: regexp match /.../n against to UTF-8 string
class Mail::Message
alias :deliver_org :deliver
def deliver
self.body = self.body.to_s.force_encoding("ASCII-8BIT")
deliver_org
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment