mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas Schwarz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@54 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
35c89c4176
commit
165097ede5
2 changed files with 33 additions and 10 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
*SVN*
|
||||||
|
|
||||||
|
* Added access to custom headers, like cc, bcc, and reply-to #268 [Andreas Schwarz]. Example:
|
||||||
|
|
||||||
|
def post_notification(recipients, post)
|
||||||
|
@recipients = recipients
|
||||||
|
@from = post.author.email_address_with_name
|
||||||
|
@headers["bcc"] = SYSTEM_ADMINISTRATOR_EMAIL
|
||||||
|
@headers["reply-to"] = "notifications@example.com"
|
||||||
|
@subject = "[#{post.account.name} #{post.title}]"
|
||||||
|
@body["post"] = post
|
||||||
|
end
|
||||||
|
|
||||||
*0.4* (5)
|
*0.4* (5)
|
||||||
|
|
||||||
* Consolidated the server configuration options into Base#server_settings= and expanded that with controls for authentication and more [Marten]
|
* Consolidated the server configuration options into Base#server_settings= and expanded that with controls for authentication and more [Marten]
|
||||||
|
|
|
@ -3,10 +3,12 @@ module ActionMailer #:nodoc:
|
||||||
#
|
#
|
||||||
# class ApplicationMailer < ActionMailer::Base
|
# class ApplicationMailer < ActionMailer::Base
|
||||||
# def post_notification(recipients, post)
|
# def post_notification(recipients, post)
|
||||||
# @recipients = recipients
|
# @recipients = recipients
|
||||||
# @subject = "[#{post.account.name} #{post.title}]"
|
# @from = post.author.email_address_with_name
|
||||||
# @body["post"] = post
|
# @headers["bcc"] = SYSTEM_ADMINISTRATOR_EMAIL
|
||||||
# @from = post.author.email_address_with_name
|
# @headers["reply-to"] = "notifications@example.com"
|
||||||
|
# @subject = "[#{post.account.name} #{post.title}]"
|
||||||
|
# @body["post"] = post
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def comment_notification(recipient, comment)
|
# def comment_notification(recipient, comment)
|
||||||
|
@ -72,7 +74,11 @@ module ActionMailer #:nodoc:
|
||||||
@@deliveries = []
|
@@deliveries = []
|
||||||
cattr_accessor :deliveries
|
cattr_accessor :deliveries
|
||||||
|
|
||||||
attr_accessor :recipients, :subject, :body, :from, :sent_on, :bcc, :cc
|
attr_accessor :recipients, :subject, :body, :from, :sent_on, :headers, :bcc, :cc
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@headers = {}
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def method_missing(method_symbol, *parameters)#:nodoc:
|
def method_missing(method_symbol, *parameters)#:nodoc:
|
||||||
|
@ -88,14 +94,18 @@ module ActionMailer #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mail(to, subject, body, from, timestamp = nil) #:nodoc:
|
def mail(to, subject, body, from, timestamp = nil, headers = nil) #:nodoc:
|
||||||
deliver(create(to, subject, body, from, timestamp))
|
deliver(create(to, subject, body, from, timestamp, headers))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(to, subject, body, from, timestamp = nil) #:nodoc:
|
def create(to, subject, body, from, timestamp = nil, headers = nil) #:nodoc:
|
||||||
m = TMail::Mail.new
|
m = TMail::Mail.new
|
||||||
m.to, m.subject, m.body, m.from = to, subject, body, from
|
m.to, m.subject, m.body, m.from = to, subject, body, from
|
||||||
m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
|
m.date = timestamp.respond_to?("to_time") ? timestamp.to_time : (timestamp || Time.now)
|
||||||
|
headers.each do |k, v|
|
||||||
|
m[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
return m
|
return m
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,9 +139,9 @@ module ActionMailer #:nodoc:
|
||||||
mailer.send(method_name, *parameters)
|
mailer.send(method_name, *parameters)
|
||||||
|
|
||||||
if String === mailer.body
|
if String === mailer.body
|
||||||
mail = create(mailer.recipients, mailer.subject, mailer.body, mailer.from, mailer.sent_on)
|
mail = create(mailer.recipients, mailer.subject, mailer.body, mailer.from, mailer.sent_on, mailer.headers)
|
||||||
else
|
else
|
||||||
mail = create(mailer.recipients, mailer.subject, render_body(mailer, method_name), mailer.from, mailer.sent_on)
|
mail = create(mailer.recipients, mailer.subject, render_body(mailer, method_name), mailer.from, mailer.sent_on, mailer.headers)
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.bcc = @bcc if @bcc
|
mail.bcc = @bcc if @bcc
|
||||||
|
|
Loading…
Reference in a new issue