Class: Alert_Email

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

Instance Method Summary collapse

Constructor Details

#initialize(destination, body) ⇒ Alert_Email

Returns a new instance of Alert_Email.



5
6
7
8
# File 'lib/Alert/Email.rb', line 5

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

Instance Method Details

#SendObject



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

def Send

message = <<MESSAGE_END
From: Agrimetrics <[email protected]>
To: #{@destination}
Subject: Agrimetrics 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