Skip to content

Instantly share code, notes, and snippets.

@bryanp
Created August 31, 2011 04:36
Show Gist options
  • Select an option

  • Save bryanp/1182830 to your computer and use it in GitHub Desktop.

Select an option

Save bryanp/1182830 to your computer and use it in GitHub Desktop.
Pakyow Mailer
class Pakyow::Mailer < Pakyow::Presenter::View
attr_accessor :subject, :sender, :content_type, :delivery_method, :delivery_options
def initialize(*args)
@sender = Configuration::Base.mailer.default_sender
@content_type = Configuration::Base.mailer.default_content_type
@delivery_method = Configuration::Base.mailer.delivery_method
@delivery_options = Configuration::Base.mailer.delivery_options
@files = []
super
end
def deliver_to(recipient, subject = nil)
@subject = subject if subject
@body = self.to_html
if recipient.is_a?(Array)
recipient.each do {|r| deliver(r)}
else
deliver(recipient)
end
end
def add_file(opts)
@files << opts
end
protected
def deliver(recipient)
mail = Mail.new do
from @sender
to recipient
subject @subject
content_type @content_type
body @body
@files.each do |file_opts|
add_file file_opts
end
end
mail.delivery_method(@delivery_method, @delivery_options)
mail.deliver
end
end
m = Pakyow::Mailer.new('emails/test')
m.add_file(:filename => 'somefile.png', :content => File.read('/somefile.png'))
m.deliver_to('bryan@metabahn.com', 'Test')
@hby
Copy link

hby commented Aug 31, 2011

What I was going to ask was to see was an example of how it is to be used in a controller with an html view that is modified and sent. That will probably clear up the questions I have as to its use.

@bryanp
Copy link
Author

bryanp commented Sep 5, 2011

See lines 49-51 for an example. Or are you looking for a more detailed example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment