Class: MonkeyMailer::Adapters::Smtp

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey-mailer/adapters/smtp.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Smtp

Options :address => ‘smtp.mandrillapp.com’, :port => 587, :domain => ‘example.com’, :user_name => ‘user’, :password => ‘password’, :authentication => ‘plain’, :enable_starttls_auto => true



15
16
17
18
19
# File 'lib/monkey-mailer/adapters/smtp.rb', line 15

def initialize(options)
  Mail.defaults do
    delivery_method :smtp, options.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
  end
end

Instance Method Details

#send_email(email) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/monkey-mailer/adapters/smtp.rb', line 21

def send_email(email)
  Mail.deliver do
    to "#{email.to_name} <#{email.to_email}>"
    from "#{email.from_name} <#{email.from_email}>"
    subject email.subject

    email.attachments.each do |attachment|
      add_file :filename => File.basename(attachment.file_path), :content => File.read(attachment.file_path)
    end

    html_part do
      content_type 'text/html; charset=UTF-8'
      body email.body
    end

    text_part do
      body email.body.nil? ? '' : email.body.gsub(/<\/?[^>]*>/, "")
    end
  end
end