vertx-mail

代码已经测试可以发送QQ邮箱,需要在QQ邮箱设置
public class MailVerticle extends AbstractVerticle {
    @Override
    public void start(Promise 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("\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "\n" +
                "
HeadingAnother Heading
row 1, cell 1row 1, cell 2
row 2, cell 1row 2, cell 2
"); 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); } }

你可能感兴趣的:(vertx-mail)