28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/gat/email.rb', line 28
def send_email(email, smtp_config)
if !smtp_config or smtp_config.empty? or !smtp_config['send_by']
raise GatgetConfigException.new('email_config is empty or missing or send_by is not defined', 'send_email')
end
domain = self.config['server_domain'] || 'localhost'
email_from = smtp_config["send_from"] || "#{ self.class.name }@#{ domain }"
case smtp_config['send_by']
when 'smtp'
server = smtp_config['smtp_config']["server"] || 'localhost'
port = smtp_config['smtp_config']["port"] || 25
user = smtp_config['smtp_config']["user"] || ""
password = smtp_config['smtp_config']["password"] || ""
begin
Net::SMTP.start(server, port, server, user, password, :login) do |smtp|
smtp.send_mail email.encoded, email_from, email.destinations
end
rescue => error
raise GatgetConfigException.new(error, "send_email(smtp)",
{ :message => "Error sending mail to '#{email.destinations}' on '#{server}:#{port}': #{error}" })
end
when 'sendmail'
Net::SMTP.start('localhost', 25) do |smtp|
smtp.send_mail email.encoded, email_from, email.destinations
end
else
raise GatgetConfigException.new("undefined send_mail method #{ smtp_config['send_by'] } at config", 'send_email')
end
end
|