Class: Howitzer::MailAdapters::Mailgun

Inherits:
Abstract
  • Object
show all
Defined in:
lib/howitzer/mail_adapters/mailgun.rb

Overview

This class represents Mailgun mail adapter

Instance Attribute Summary

Attributes inherited from Abstract

#message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#initialize

Constructor Details

This class inherits a constructor from Howitzer::MailAdapters::Abstract

Class Method Details

.find(recipient, subject, wait:) ⇒ Object

Note:

emails are stored for 3 days only!

Finds an email in storage

Parameters:

  • recipient (String)

    an email

  • subject (String)
  • wait (Integer)

    how much time is required to wait an email

Raises:



16
17
18
19
20
21
22
23
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 16

def self.find(recipient, subject, wait:)
  message = {}
  retryable(find_retry_params(wait)) { message = retrieve_message(recipient, subject) }
  return new(message) if message.present?

  raise Howitzer::EmailNotFoundError,
        "Message with subject '#{subject}' for recipient '#{recipient}' was not found."
end

Instance Method Details

#html_bodyString

Returns html body of the email message.

Returns:

  • (String)

    html body of the email message



33
34
35
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 33

def html_body
  message['stripped-html']
end

#mail_fromString

Returns an email address specified in ‘From` field.

Returns:

  • (String)

    an email address specified in ‘From` field



45
46
47
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 45

def mail_from
  message['From']
end

#mime_partArray

Returns attachments.

Returns:

  • (Array)

    attachments



69
70
71
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 69

def mime_part
  message['attachments']
end

#mime_part!Array

Returns attachments.

Returns:

  • (Array)

    attachments

Raises:



76
77
78
79
80
81
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 76

def mime_part!
  files = mime_part
  return files if files.present?

  raise Howitzer::NoAttachmentsError, 'No attachments were found.'
end

#plain_text_bodyString

Returns plain text body of the email message.

Returns:

  • (String)

    plain text body of the email message



27
28
29
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 27

def plain_text_body
  message['body-plain']
end

#received_timeString

Returns when email was received.

Returns:

  • (String)

    when email was received



57
58
59
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 57

def received_time
  message['Received'][/\w+, \d+ \w+ \d+ \d+:\d+:\d+ -\d+ \(\w+\)$/]
end

#recipientsString

Returns recipient emails separated with ‘, `.

Returns:

  • (String)

    recipient emails separated with ‘, `



51
52
53
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 51

def recipients
  message['To'].split ', '
end

#sender_emailString

Returns a real sender email address.

Returns:

  • (String)

    a real sender email address



63
64
65
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 63

def sender_email
  message['sender']
end

#textString

Returns stripped text.

Returns:

  • (String)

    stripped text



39
40
41
# File 'lib/howitzer/mail_adapters/mailgun.rb', line 39

def text
  message['stripped-text']
end