MailService
simple example:
require 'vertx-mail/mail_service'
mailConfig = {
'hostname' => "mail.example.com",
'port' => 587,
'username' => "user",
'password' => "pw"
}
mailService = VertxMail::MailService.create(vertx, mailConfig)
email = {
'from' => "address@example.com",
'to' => "address@example.com",
'subject' => "meaningful subject",
'text' => "this is a message",
'html' => "HTML message <a href=\"http://vertx.io\">vertx</a>"
}
mailService.send_mail(email) { |result,result_err|
if (result_err == nil)
puts result
else
puts "got exception"
result_err.print_stack_trace()
end
}
attachments can be added as Buffer object
require 'vertx-mail/mail_service'
require 'vertx/buffer'
# default config will use localhost:25
mailConfig = {
}
mailService = VertxMail::MailService.create(vertx, mailConfig)
email = {
'from' => "address@example.com",
'to' => "address@example.com",
'subject' => "your file",
'text' => "please take a look at the attached file"
}
attachment = {
'name' => "file.dat",
'data' => Vertx::Buffer.buffer("ASDF1234\u0000\u0001\u0080\u00FF\n")
}
email['attachment'] = attachment
mailService.send_mail(email) { |result,result_err|
if (result_err == nil)
puts result
else
puts "got exception"
result_err.print_stack_trace()
end
}
the service interface can send mails via the eventbus if the service is running on other machine in the cluster
require 'vertx-mail/mail_service'
mailService = VertxMail::MailService.create_event_bus_proxy(vertx, "vertx.mail")
email = {
'from' => "user@example.com",
'bounceAddress' => "bounce@example.com",
'to' => "user@example.com"
}
mailService.send_mail(email) { |result,result_err|
puts "mail finished"
if (result_err == nil)
puts result
else
puts "got exception"
result_err.print_stack_trace()
end
}