Class: LeanMail::Deliver

Inherits:
Object
  • Object
show all
Defined in:
contrib/lib/lean_mail.rb

Overview

Email deliverer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeliver

Returns a new instance of Deliver.



62
63
64
65
66
67
68
69
70
71
72
# File 'contrib/lib/lean_mail.rb', line 62

def initialize
  @user = ENV.fetch('SMTP_USER', nil)
  @password = ENV.fetch('SMTP_PASSWORD', nil)
  @from = ENV.fetch('SMTP_FROM')

  @host = ENV.fetch('SMTP_HOST')
  @port = ENV.fetch('SMTP_PORT', 25)
  @security = ENV.fetch('SMTP_SECURITY', nil)

  initialize_smtp
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



60
61
62
# File 'contrib/lib/lean_mail.rb', line 60

def data
  @data
end

Instance Method Details

#call(to, subject, body) ⇒ Deliver

Send email.

Parameters:

  • to (Array, String)

    In the format Name <user@mail> or user@mail.

  • subject (String)
  • body (String)

Returns:



80
81
82
83
84
85
86
87
88
# File 'contrib/lib/lean_mail.rb', line 80

def call(to, subject, body)
  @data = Data.new(@from, to, subject, body)

  @smtp.start(Socket.gethostname, @user, @password, :plain) do |smtp|
    smtp.send_message(@data.to_s, extract_addr(@from), extract_addrs(to))
  end

  self
end