Created
January 9, 2009 21:11
-
-
Save xwmx/45283 to your computer and use it in GitHub Desktop.
ActionMailer Monkeypatching
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
class ActionMailer::Base | |
helper ActionView::Helpers::UrlHelper | |
def generic_mailer(options) | |
@recipients = options[:recipients] || (Settings.mailer_to_address if Settings.table_exists?) | |
@from = options[:from] || (Settings.mailer_from_address if Settings.table_exists?) | |
@cc = options[:cc] || "" | |
@bcc = options[:bcc] || "" | |
@subject = options[:subject] || "" | |
@body = options[:body] || {} | |
@headers = options[:headers] || {} | |
@charset = options[:charset] || "utf-8" | |
@content_type = options[:content_type] || "text/plain" | |
end | |
def self.add_recipients(addresses, address) | |
if addresses.blank? | |
address | |
else | |
addresses << ";#{address}" | |
end | |
end | |
=begin | |
#add blocks like this to controllers | |
class ContactMailer < ActionMailer::Base | |
def contact_us(options) | |
self.generic_mailer(options) | |
end | |
end | |
#call like this | |
ContactMailer.deliver_contact_us( | |
:recipients => "[email protected]", | |
:body => { | |
:name => params[:name], | |
:phone => params[:phone], | |
:email => params[:email], | |
:message => params[:message] | |
}, | |
:from => "[email protected]" | |
) | |
=end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment