Class: Hanami::Mailer::Delivery::SMTP

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/mailer/delivery/smtp.rb

Overview

SMTP delivery method

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ SMTP

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize SMTP delivery with configuration

Parameters:

  • options (Hash)

    SMTP configuration options



17
18
19
# File 'lib/hanami/mailer/delivery/smtp.rb', line 17

def initialize(**options)
  @options = options
end

Instance Method Details

#call(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deliver a message via SMTP

Parameters:

  • message (Message)

    the message to deliver



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hanami/mailer/delivery/smtp.rb', line 26

def call(message)
  mail = to_mail(message)
  mail.delivery_method(:smtp, @options)

  delivery_exception = nil
  begin
    mail.deliver!
  rescue Net::SMTPError => exception
    delivery_exception = exception
  end

  Result.new(
    message: message,
    response: mail,
    success: delivery_exception.nil?,
    error: delivery_exception
  )
end