Skip to content

Instantly share code, notes, and snippets.

@ippy04
Created March 17, 2011 01:20
Show Gist options
  • Save ippy04/873683 to your computer and use it in GitHub Desktop.
Save ippy04/873683 to your computer and use it in GitHub Desktop.
Delivery Method for Mailchimp STS and Amazon SES using Uakari
class MailchimpDeliveryMethod
attr_accessor :settings
def initialize(values = {})
self.settings = {:track_opens => true,
:track_clicks => true
}.merge!(values)
end
def deliver!(mail)
message = {
:track_opens => settings[:track_opens],
:track_clicks => settings[:track_clicks],
:tags => [Rails.env.to_s],
:message => {
:subject => mail.subject,
:from_email => mail.from.first,
:to_email => mail.to
}
}
message[:reply_to] = mail.reply_to if mail.reply_to
message[:from_name] = $1.strip if /(^.*)</.match(mail.header['from'].value)
message[:message][:text] = body_text(mail) unless self.html?(mail)
message[:message][:html] = body_html(mail) if self.html?(mail)
Mailchimp::Service.send_email(message)
end
def html?(mail)
mail.content_type && mail.content_type.include?('text/html')
end
def body_html(mail)
if mail.html_part.nil?
mail.body.to_s if self.html?(mail)
else
mail.html_part.body.to_s
end
end
def body_text(mail)
if mail.text_part.nil?
mail.body.to_s
else
mail.text_part.body.to_s
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment