class StatusChecker::Email

Public Class Methods

new(receivers) click to toggle source
# 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 = 'technical_root@mail.ru'
  @password = 'qwerty123456'
  @smtp = Net::SMTP.new(@addres, @port)
  @smtp.enable_tls
end

Public Instance Methods

send(url, response) click to toggle source
# 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

Private Instance Methods

message(url, response, email) click to toggle source
# File lib/status_checker/email.rb, line 32
def message(url, response, email)
  "From:<#{@user_name}>\n" \
  "To:<#{email}>\n" \
  "MIME-Version: 1.0\n" \
  "Content-type: text/html\n" \
  "Subject: Attention!!!\n" \
  "<h1 style='color:red'><b>!!!ATTENTION!!!</b></h1>\n" \
  "<p>The host #{url} #{response.message} and has " \
  "<b>code: #{response.code}</b></p>"
end