vertx-mail
2019-09-26 本文已影响0人
anyly
代码已经测试可以发送QQ邮箱,需要在QQ邮箱设置
public class MailVerticle extends AbstractVerticle {
@Override
public void start(Promise<Void> startPromise) throws Exception {
MailConfig config = new MailConfig();
config.setHostname("smtp.qq.com");
config.setSsl(true);
config.setPort(465);
config.setStarttls(StartTLSOptions.REQUIRED);
config.setUsername("112972***@qq.com");
config.setPassword("***lzyrghdh");
MailClient mailClient = MailClient.createShared(vertx, config);
MailMessage message = new MailMessage();
message.setSubject("vertx");
message.setFrom("11297***@qq.com");
// message.setTo("huarj@***");
message.setCc("112**@qq.com");
message.setHtml("<table border=\"1\">\n" +
"<tr>\n" +
"<th>Heading</th>\n" +
"<th>Another Heading</th>\n" +
"</tr>\n" +
"<tr>\n" +
"<td>row 1, cell 1</td>\n" +
"<td>row 1, cell 2</td>\n" +
"</tr>\n" +
"<tr>\n" +
"<td>row 2, cell 1</td>\n" +
"<td>row 2, cell 2</td>\n" +
"</tr>\n" +
"</table>");
mailClient.sendMail(message, result -> {
if (result.failed()) {
result.cause().printStackTrace();
System.out.println(result.cause().getMessage());
return;
}
});
}
public static void main(String[] args) {
DeploymentOptions options = new DeploymentOptions()
.setWorker(true)
.setInstances(1)
.setWorkerPoolName("the-specific-pool")
.setWorkerPoolSize(5);
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new MailVerticle(), options);
}
}