Class: Mailee::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/mailee/action_mailer.rb

Overview

The Mailer class is responsible for making the mailee gem ActionMailer compatible.

USAGE:

If you want to use Mailee to send all your systems emails, simply
configure the environment (dev or prod) like this:

  config.action_mailer.delivery_method = Mailee::Mailer

But if you wanna send just a certain mailer with Mailee, add
"send_with_mailee" on a per mailer basis

  class Notifications < ActionMailer::Base
    send_with_mailee
  end

One important thing, is to add the sender's name to the default "from" in
your mailer, this way:

  default :from => "Your name <[email protected]>"

And don't forget to config your domain SPF!

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Mailer

Returns a new instance of Mailer.



27
28
# File 'lib/mailee/action_mailer.rb', line 27

def initialize config
end

Instance Method Details

#deliver!(mail) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/mailee/action_mailer.rb', line 29

def deliver! mail
  from_name = mail.header['from'].to_s.scan(/(.+?) <.+?>$/).to_s      
  message = Mailee::Message.create :title => mail.subject, :subject => mail.subject, :from_name => from_name, :from_email => mail.from.first, :emails => mail.to.join(' '), :html => mail.body.to_s
  result = message.ready(mail.date)
  mail.instance_eval{ self.class.send('attr_accessor', :mailee_message); self.mailee_message = message }
  self 
end