Class: StatusChecker::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/status_checker/email.rb

Instance Method Summary collapse

Constructor Details

#initialize(receivers) ⇒ Email

Returns a new instance of Email.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/status_checker/email.rb', line 6

def initialize(receivers)
  raise ArgumentError, "receivers can't be empty" if receivers.empty?
  @receivers = receivers
  @addres = 'smtp.mail.ru'
  @port = 465
  @domain = 'mail.ru'
  @authentication = :plain
  @user_name = '[email protected]'
  @password = 'qwerty123456'
  @smtp = Net::SMTP.new(@addres, @port)
  @smtp.enable_tls
end

Instance Method Details

#send(url, response) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/status_checker/email.rb', line 19

def send(url, response)
  begin
    @smtp.start(@domain, @user_name, @password, @authentication)
    @receivers.each do |email|
      @smtp.send_message message(url, response, email), @user_name, email
    end
  ensure
    @smtp.finish
  end
end