class ArMailerAWS::Clients::Mandrill

Constants

REJECT_HEADERS

Public Class Methods

new(options={}) click to toggle source
Calls superclass method ArMailerAWS::Clients::Base::new
# File lib/ar_mailer_aws/clients/mandrill.rb, line 11
def initialize(options={})
  super
  @service = ::Mandrill::API.new settings[:key]
end

Public Instance Methods

email_json(email) click to toggle source
# File lib/ar_mailer_aws/clients/mandrill.rb, line 38
def email_json(email)
  mail = Mail.new(email.mail)
  headers = mail.header.reject{|h| REJECT_HEADERS.include?(h.name) }.map { |h| [h.name, h.value] }.to_hash
  {
      'subject' => mail.subject.to_s.force_encoding('UTF-8'),
      'html' => mail.body.to_s.force_encoding('UTF-8'),
      'headers' => headers,
      'from_email' => email.from,
      'track_opens' => false,
      'track_clicks' => false,
      'to' => [{'email' => email.to, 'type' => 'to'}]
  }
end
send_email(email) click to toggle source
# File lib/ar_mailer_aws/clients/mandrill.rb, line 28
def send_email(email)
  log "send email to #{email.to}"
  email_json_hash = email_json(email)
  client_log email_json_hash, :debug
  resp = @service.messages.send email_json_hash
  client_log resp, :debug
  email.destroy
  @sent_count += 1
end
send_emails(emails) click to toggle source
# File lib/ar_mailer_aws/clients/mandrill.rb, line 16
def send_emails(emails)
  emails.each do |email|
    return if exceed_quota?
    begin
      check_rate
      send_email(email)
    rescue => e
      handle_email_error(e, email)
    end
  end
end