Class: Alert_Email

Inherits:
Object
  • Object
show all
Defined in:
lib/Alert/Email.rb

Overview

Email alert class Uses localhost for sending email - Probably need to change this in the future.

Instance Method Summary collapse

Constructor Details

#initialize(destination, body) ⇒ Alert_Email

Returns a new instance of Alert_Email.



7
8
9
10
# File 'lib/Alert/Email.rb', line 7

def initialize( destination, body )
	@destination = destination
	@body = body
end

Instance Method Details

#SendObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/Alert/Email.rb', line 12

def Send

message = <<MESSAGE_END
From: #{ENV['APP_NAME']} <[email protected]>
To: #{@destination}
Subject: #{ENV['APP_NAME']} Alert

#{@body}
.
MESSAGE_END

Net::SMTP.start('localhost') do |smtp|
 smtp.send_message message, '[email protected]',
                            @destination
end

rescue Errno::ECONNREFUSED => e
   puts "*** Conection refused while attempting to connect to SMTP server"
   puts "*** Recipient, #{@destination}. Body,"
   puts "*** #{@body}"
end