Vert.x 2.x is deprecated - use instead http://vertx.io/docs/vertx-mail-client/java/
This module allows emails to be sent via SMTP.
This module requires a mail server to be available.
The module name is mailer
.
The mailer module requires the following configuration:
{
"address": <address>,
"host": <host>,
"port": <port>,
"ssl": <ssl>,
"auth": <auth>,
"username": <username>,
"password": <password>,
"content_type": <content_type>
}
Let's take a look at each field in turn:
address
The main address for the busmod. Every busmod has a main address.host
Host name or ip address of the mail server instance. Defaults tolocalhost
.port
Port at which the mail server is listening. Defaults to25
.ssl
Iftrue
then use ssl, otherwise don't use ssl. Default isfalse
.auth
Iftrue
use authentication, otherwise don't use authentication. Default isfalse
.username
If using authentication, the username. Default isnull
.password
If using authentication, the password. Default isnull
.content_type
If you want to send HTML email body, then set totext/html
. Default istext/plain
.
For example, to send to a local server on port 25:
{
"address": "test.my_mailer"
}
Or to a gmail account:
{
"address": "test.my_mailer"
"host": "smtp.googlemail.com",
"port": 465,
"ssl": true,
"auth": true,
"username": "tim",
"password": "password"
}
To send an email just send a JSON message to the main address of the mailer. The JSON message representing the email should have the following structure:
{
"from": <from>,
"to": <to|to_list>,
"cc": <cc|cc_list>
"bcc": <bcc|bcc_list>
"subject": <subject>
"body": <body>,
"headers": <headers_list>
}
Where:
from
is the sender address of the email. Must be a well-formed email address.to
to is either a single well formed email address representing the recipient or a JSON array of email addresses representing the recipients. This field is mandatory.cc
to is either a single well formed email address representing a cc recipient or a JSON array of email addresses representing the cc list. This field is optional.bcc
to is either a single well formed email address representing a bcc recipient or a JSON array of email addresses representing the bcc list. This field is optional.subject
is the subject of the email. This field is mandatory.body
is the body of the email. This field is mandatory.headers
is a JSON array of JSON object representing the name of an header and it's value. This field is optional.
For example, to send a mail to a single recipient:
{
"from": "tim@wibble.com",
"to": "bob@wobble.com",
"subject": "Congratulations on your new armadillo!",
"body": "Dear Bob, great to here you have purchased......"
}
Or to send to multiple recipients:
{
"from": "tim@wibble.com",
"to": ["bob@wobble.com", "jane@tribble.com"],
"subject": "Sadly, my aardvark George, has been arrested.",
"body": "All, I'm afraid George was found...."
}
Or to send to multiple recipients with additional headers:
{
"from": "tim@wibble.com",
"to": ["bob@wobble.com", "jane@tribble.com"],
"subject": "Sadly, my aardvark George, has been arrested.",
"body": "All, I'm afraid George was found....",
"headers": [{"name": "X-My-Header","value": "Header's value"}]
}