Skip to content

Instantly share code, notes, and snippets.

@xwmx
Created January 9, 2009 21:11
Show Gist options
  • Save xwmx/45283 to your computer and use it in GitHub Desktop.
Save xwmx/45283 to your computer and use it in GitHub Desktop.
ActionMailer Monkeypatching
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 => "user@example.com",
:body => {
:name => params[:name],
:phone => params[:phone],
:email => params[:email],
:message => params[:message]
},
:from => "other.user@example.com"
)
=end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment