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
|
# File 'lib/maildis/dispatcher.rb', line 10
def dispatch(options = {})
result = {sent: [], not_sent: []}
init_logger options[:logger]
options[:recipients].each do |recipient|
begin
Pony.mail({
to: recipient.to_email,
from: options[:sender].to_email,
subject: options[:subject],
html_body: TemplateRenderer.render(options[:templates][:html], recipient.merge_fields),
body: TemplateRenderer.render(options[:templates][:plain], recipient.merge_fields),
via: :smtp,
via_options: {address: options[:server].host,
port: options[:server].port,
user_name: options[:server].username,
password: options[:server].password}
})
info "Sent: #{recipient.to_email}"
result[:sent] << recipient
rescue => e
error "Error: #{recipient.to_email} | #{e.message}"
result[:not_sent] << {recipient: recipient, reason: e.message}
end
end
result
end
|