41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/watcher_action/send_mail.rb', line 41
def execute(event)
msg = RMail::Message.new
msg..to = @mail_to
receipient = msg..to.to_s.split(',').first
msg..from = @sender
msg..subject = @subject % [event.message]
msg..date = Time.now
if(@body.to_s == 'xml')
msg.body = event.to_xml
elsif(@body)
msg.body = @body % [event.message]
else
msg.body = "The #{event.watcher.class.name} watcher of your watchdog triggered\nan event at #{event.timestamp}:\n#{event.message}"
end
smtp_params = [@server, @port]
if(@user && @pass)
smtp_params.concat([nil, @user, @pass, @authentication])
end
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) if(@enable_tls)
Thread.new(smtp_params, msg, @sender, @mail_to) do |params, msg, sender, mail_to|
begin
Net::SMTP.start(*params) do |smtp|
smtp.send_message(msg.to_s, sender, mail_to)
end
dog_log.debug('SMTP Thread') { "Sent mail to #{mail_to} through #{params.first}" }
rescue Exception => e
dog_log.error('SMTP Thread') { "Could not send mail to #{mail_to} on #{params.first}: #{e.message}" }
end
end
rescue Exception => e
dog_log.error('SMTP Action') { "Could not send mail to #{@mail_to} on #{@server}: #{e.message}" }
end
|