Class: RailsMail::DeliveryMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_mail/delivery_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DeliveryMethod

Returns a new instance of DeliveryMethod.



3
4
# File 'lib/rails_mail/delivery_method.rb', line 3

def initialize(options = {})
end

Instance Method Details

#deliver!(mail) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_mail/delivery_method.rb', line 6

def deliver!(mail)
  RailsMail::Email.create!(
    from: mail.from&.first,
    to: mail.to,
    cc: mail.cc,
    bcc: mail.bcc,
    subject: mail.subject,
    text_part: extract_mail_body_by_type(mail, "text/plain"),
    html_part: extract_mail_body_by_type(mail, "text/html"),
    content_type: mail.content_type,
    attachments: mail.attachments.map { |a| { filename: a.filename, content_type: a.content_type.split(";").first } }
  )
rescue => e
  Rails.logger.error("Failed to deliver email: #{e.message}")
  raise e
end