Class: Mail::MadMimi
- Inherits:
-
Object
- Object
- Mail::MadMimi
- Defined in:
- lib/mail/mad_mimi.rb,
lib/mail/mad_mimi/version.rb
Overview
Mail::MadMimi is a delivery method for Mail
. It uses the MadMimi
library to send mail via Mad Mimi.
Defined Under Namespace
Modules: SetMailerAction Classes: Error
Constant Summary collapse
- VERSION =
"1.1.0"
Instance Attribute Summary collapse
-
#mimi ⇒ Object
Returns the value of attribute mimi.
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #body(mail, mime_type) ⇒ Object
- #deliver!(mail) ⇒ Object
- #html(mail) ⇒ Object
-
#initialize(settings = {}) ⇒ MadMimi
constructor
Any settings given here will be passed to Mad Mimi.
- #options_from_mail(mail) ⇒ Object
- #text(mail) ⇒ Object
Constructor Details
#initialize(settings = {}) ⇒ MadMimi
Any settings given here will be passed to Mad Mimi.
:email
and :api_key
are required.
14 15 16 17 18 19 20 21 |
# File 'lib/mail/mad_mimi.rb', line 14 def initialize(settings = {}) unless settings[:email] && settings[:api_key] raise Error, "Missing :email and :api_key settings" end self.settings = settings self.mimi = ::MadMimi.new settings[:email], settings[:api_key] end |
Instance Attribute Details
#mimi ⇒ Object
Returns the value of attribute mimi.
9 10 11 |
# File 'lib/mail/mad_mimi.rb', line 9 def mimi @mimi end |
#settings ⇒ Object
Returns the value of attribute settings.
9 10 11 |
# File 'lib/mail/mad_mimi.rb', line 9 def settings @settings end |
Instance Method Details
#body(mail, mime_type) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/mail/mad_mimi.rb', line 50 def body(mail, mime_type) if part = mail.find_first_mime_type(mime_type) part.body.to_s elsif mail.mime_type == mime_type mail.body.to_s end end |
#deliver!(mail) ⇒ Object
58 59 60 61 62 |
# File 'lib/mail/mad_mimi.rb', line 58 def deliver!(mail) mimi.send_mail((mail), {}).tap do |response| raise Error, response if response.to_i.zero? # no transaction id end end |
#html(mail) ⇒ Object
42 43 44 |
# File 'lib/mail/mad_mimi.rb', line 42 def html(mail) body(mail, "text/html") end |
#options_from_mail(mail) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mail/mad_mimi.rb', line 23 def (mail) settings.merge( :recipients => mail[:to].to_s, :from => mail[:from].to_s, :bcc => mail[:bcc].to_s, :subject => mail.subject, :raw_html => html(mail), :raw_plain_text => text(mail) ).tap do || if mail.respond_to? :mailer_action [:promotion_name] = mail.mailer_action end .merge!(mail[:mad_mimi].value) if mail[:mad_mimi] .reject! {|k,v| v.nil? } end end |
#text(mail) ⇒ Object
46 47 48 |
# File 'lib/mail/mad_mimi.rb', line 46 def text(mail) body(mail, "text/plain") || mail.body.to_s end |