Class: MailHandler::Sending::SMTPSender
- Defined in:
- lib/mailhandler/sending/smtp.rb
Overview
class which describes methods to send and receive emails
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#openssl_verify_mode ⇒ Object
Returns the value of attribute openssl_verify_mode.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#save_response ⇒ Object
Returns the value of attribute save_response.
-
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Sender
Instance Method Summary collapse
- #can_authenticate? ⇒ Boolean
-
#initialize ⇒ SMTPSender
constructor
A new instance of SMTPSender.
- #send(email) ⇒ Object
- #send_raw_email(text_email, smtp_from, smtp_to) ⇒ Object
- #timeout=(value) ⇒ Object
- #valid_response?(response) ⇒ Boolean
Constructor Details
#initialize ⇒ SMTPSender
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
#address ⇒ Object
Returns the value of attribute address.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def address @address end |
#authentication ⇒ Object
Returns the value of attribute authentication.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def authentication @authentication end |
#domain ⇒ Object
Returns the value of attribute domain.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def domain @domain end |
#open_timeout ⇒ Object
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_mode ⇒ Object
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 |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def port @port end |
#read_timeout ⇒ Object
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_response ⇒ Object
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_ssl ⇒ Object
Returns the value of attribute use_ssl.
10 11 12 |
# File 'lib/mailhandler/sending/smtp.rb', line 10 def use_ssl @use_ssl end |
#username ⇒ Object
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
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().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
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 |