Class: MailHandler::Sending::SMTPSender

Inherits:
Sender
  • Object
show all
Defined in:
lib/mailhandler/sending/smtp.rb

Overview

class which describes methods to send and receive emails

Instance Attribute Summary collapse

Attributes inherited from Sender

#type

Instance Method Summary collapse

Constructor Details

#initializeSMTPSender

Returns a new instance of SMTPSender.



13
14
15
16
17
18
19
20
21
22
# File 'lib/mailhandler/sending/smtp.rb', line 13

def initialize
  super :smtp

  @authentication = 'plain'
  @use_ssl = true
  @save_response = true

  @open_timeout = 60
  @read_timeout = 60
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def address
  @address
end

#authenticationObject

Returns the value of attribute authentication.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def authentication
  @authentication
end

#domainObject

Returns the value of attribute domain.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def domain
  @domain
end

#open_timeoutObject

Returns the value of attribute open_timeout.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def open_timeout
  @open_timeout
end

#openssl_verify_modeObject

Returns the value of attribute openssl_verify_mode.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def openssl_verify_mode
  @openssl_verify_mode
end

#passwordObject

Returns the value of attribute password.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def password
  @password
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def port
  @port
end

#read_timeoutObject

Returns the value of attribute read_timeout.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def read_timeout
  @read_timeout
end

#save_responseObject

Returns the value of attribute save_response.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def save_response
  @save_response
end

#use_sslObject

Returns the value of attribute use_ssl.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/mailhandler/sending/smtp.rb', line 10

def username
  @username
end

Instance Method Details

#can_authenticate?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/mailhandler/sending/smtp.rb', line 36

def can_authenticate?
  method_name = 'start_smtp_session' # Mail::SMTP private method
  configure_sending(Mail.new).delivery_method.send(method_name)
  true
rescue Net::SMTPAuthenticationError
  false
end

#send(email) ⇒ Object



24
25
26
27
28
# File 'lib/mailhandler/sending/smtp.rb', line 24

def send(email)
  verify_email(email)
  email = configure_sending(email)
  save_response ? email.deliver! : email.deliver
end

#send_raw_email(text_email, smtp_from, smtp_to) ⇒ Object



30
31
32
33
34
# File 'lib/mailhandler/sending/smtp.rb', line 30

def send_raw_email(text_email, smtp_from, smtp_to)
  # use same settings as when sending mail created with Mail gem
  response = Mail::SMTP.new(delivery_options).deliver_raw!(text_email, smtp_from, smtp_to)
  save_response ? response : nil
end

#timeout=(value) ⇒ Object



48
49
50
51
# File 'lib/mailhandler/sending/smtp.rb', line 48

def timeout=(value)
  @read_timeout = value
  @open_timeout = value
end

#valid_response?(response) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mailhandler/sending/smtp.rb', line 44

def valid_response?(response)
  response.string.to_s.downcase.include?('250 2.0.0 ok')
end