Created
August 9, 2011 11:55
-
-
Save tyabe/1133843 to your computer and use it in GitHub Desktop.
Railsの config/initializers の下に置いておくメール設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 => "[email protected]", | |
'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