Module: Mailtrap::Mail

Defined in:
lib/mailtrap/mail.rb,
lib/mailtrap/mail/base.rb,
lib/mailtrap/mail/from_template.rb

Defined Under Namespace

Classes: Base, FromTemplate

Class Method Summary collapse

Class Method Details

.from_message(message) ⇒ Mailtrap::Mail::Base

Parameters:

  • message (Mail::Message)

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mailtrap/mail.rb', line 14

def from_message(message) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  Mailtrap::Mail::Base.new(
    from: prepare_addresses(address_list(message['from'])&.addresses).first,
    to: prepare_addresses(address_list(message['to'])&.addresses),
    cc: prepare_addresses(address_list(message['cc'])&.addresses),
    bcc: prepare_addresses(address_list(message['bcc'])&.addresses),
    subject: message.subject,
    text: prepare_text_part(message),
    html: prepare_html_part(message),
    headers: prepare_headers(message),
    attachments: prepare_attachments(message.attachments),
    category: message['category']&.unparsed_value,
    custom_variables: message['custom_variables']&.unparsed_value
  )
end