forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailServiceExample.java
56 lines (43 loc) · 1.69 KB
/
MailServiceExample.java
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package io.vertx.example.mail;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.example.util.Runner;
import io.vertx.ext.mail.MailMessage;
import io.vertx.ext.mail.MailService;
/**
* send a mail via event bus to the mail service running on another machine
*
* @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a>
*/
public class MailServiceExample extends AbstractVerticle {
public static final String MAIL_SERVICE_VERTICLE = "io.vertx.ext.mail.MailServiceVerticle";
// Convenience method so you can run it in your IDE
public static void main(String[] args) {
Runner.runExample(MailServiceExample.class);
}
public void start() {
// Start a local STMP server, remove this line if you want to use your own server.
// It just prints the sent message to the console
LocalSmtpServer.start(2527);
JsonObject config = new JsonObject();
config.put("port", 2527);
config.put("address", "vertx.mail");
vertx.deployVerticle(MAIL_SERVICE_VERTICLE, new DeploymentOptions().setConfig(config), done -> {
MailService mailService = MailService.createEventBusProxy(vertx, "vertx.mail");
MailMessage email = new MailMessage()
.setBounceAddress("[email protected]")
.setTo("[email protected]")
.setSubject("this message has no content at all");
mailService.sendMail(email, result -> {
if (result.succeeded()) {
System.out.println(result.result());
System.out.println("Mail sent");
} else {
System.out.println("got exception");
result.cause().printStackTrace();
}
});
});
}
}