class MailHandler::Sending::SMTPSender
class which describes methods to send and receive emails
Attributes
address[RW]
authentication[RW]
domain[RW]
open_timeout[RW]
openssl_verify_mode[RW]
password[RW]
port[RW]
read_timeout[RW]
save_response[RW]
use_ssl[RW]
username[RW]
Public Class Methods
new()
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 23 def initialize @type = :smtp @authentication = 'plain' @use_ssl = false @save_response = true @open_timeout = 60 @read_timeout = 60 end
Public Instance Methods
send(email)
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 33 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)
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 39 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)
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 49 def timeout=(value) @read_timeout = value @open_timeout = value end
valid_response?(response)
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 45 def valid_response?(response) response.string.to_s.downcase.include?('250 2.0.0 ok') end
Private Instance Methods
configure_sending(email)
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 56 def configure_sending(email) email.delivery_method :smtp, delivery_options email end
delivery_options()
click to toggle source
# File lib/mailhandler/sending/smtp.rb, line 61 def delivery_options { address: address, port: port, domain: domain, user_name: username, password: password, authentication: @authentication, enable_starttls_auto: @use_ssl, openssl_verify_mode: @openssl_verify_mode, return_response: save_response, open_timeout: open_timeout, read_timeout: read_timeout } end