-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclogger.rb
executable file
·42 lines (34 loc) · 1.14 KB
/
clogger.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'net/smtp'
class CLogger
def initialize
@methods = []
end
def log(message)
@message = message
@methods.each { |x| send(x) }
end
def add_smtp_out(smtp, port, from, to, subject)
@mail = {}
@mail[:smtp], @mail[:port], @mail[:from], @mail[:to], @mail[:subject] = smtp, port, from, to, subject
@methods.push(:mail)
end
def mail
Net::SMTP.start(@mail[:smtp], @mail[:port]) { |smtp|
smtp.open_message_stream(@mail[:from], @mail[:to]) { |f|
f.puts "From: #{@mail[:from]}"
f.puts "To: #{@mail[:to]}"
f.puts "Subject: #{@mail[:subject]}"
f.puts ""
f.puts "log message follows: #{@message}"
}
}
end
end
def test
require 'yaml'
c = YAML.load_file(File.dirname(__FILE__) + "/conf.yaml")
l = CLogger.new
l.add_smtp_out(c['config']['mail_log']['smtp'], c['config']['mail_log']['port'], c['config']['mail_log']['from'], c['config']['mail_log']['to'], c['config']['mail_log']['subject'])
l.log("test mail")
end
test if $0 == __FILE__