ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2010年6月30日 星期三
rails 設定多個 smtp account 寄信
Using multiple SMTP accounts with Rails & ActionMailer
可利用此技巧, 達到多SMTP 寄信的目的
#action_mailer.yml
production:
website1:
domain: "gary@superfriends.com"
user_name: gary
password: superduper
address: smtp.gmail.com
port: 587
authentication: :plain
website2:
domain: mysupercooldomain.com
user_name: ABCDEF
password: blahblah
address: mail.authsmtp.com
port: 25
authentication: :plain
#app/models/mailer1.rb
class Website1 < ActionMailer::Base
def load_settings
options = YAML.load_file("#{RAILS_ROOT}/config/action_mailer.yml")[RAILS_ENV]["website1"]
@@smtp_settings = {
:address => options["address"],
:port => options["port"],
:domain => options["domain"],
:authentication => options["authentication"],
:user_name => options["user_name"],
:password => options["password"]
}
end
def welcome_email(recipient, sent_at = Time.now)
load_settings
@subject = 'Thank you for visiting website 1'
@recipients = RAILS_ENV == "production" ? recipient : "cavneb@gmail.com"
@from = 'gary@superfriends.com'
@sent_on = sent_at
end
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言