diff --git a/mail-examples/src/main/java/io/vertx/example/mail/LocalSmtpServer.java b/mail-examples/src/main/java/io/vertx/example/mail/LocalSmtpServer.java
index ec597ee39..47fc0dd87 100644
--- a/mail-examples/src/main/java/io/vertx/example/mail/LocalSmtpServer.java
+++ b/mail-examples/src/main/java/io/vertx/example/mail/LocalSmtpServer.java
@@ -1,11 +1,16 @@
package io.vertx.example.mail;
+import org.apache.commons.io.IOUtils;
import org.subethamail.smtp.auth.LoginFailedException;
import org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory;
import org.subethamail.smtp.auth.UsernamePasswordValidator;
+import org.subethamail.smtp.helper.SimpleMessageListener;
import org.subethamail.smtp.helper.SimpleMessageListenerAdapter;
import org.subethamail.smtp.server.SMTPServer;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* @author Clement Escoffier
*/
@@ -30,4 +35,18 @@ public static void startWithAuth(int port) {
server.start();
}
+ private static class MyMessageListener implements SimpleMessageListener {
+
+
+ @Override
+ public boolean accept(String from, String recipient) {
+ return true;
+ }
+
+ @Override
+ public void deliver(String from, String recipient, InputStream data) throws IOException {
+ System.out.println("Sending mail from " + from + " to " + recipient
+ + " (size: " + IOUtils.toByteArray(data).length + " bytes)");
+ }
+ }
}
diff --git a/mail-examples/src/main/java/io/vertx/example/mail/MailHeaders.java b/mail-examples/src/main/java/io/vertx/example/mail/MailHeaders.java
index d68010df2..c592fe44f 100644
--- a/mail-examples/src/main/java/io/vertx/example/mail/MailHeaders.java
+++ b/mail-examples/src/main/java/io/vertx/example/mail/MailHeaders.java
@@ -1,6 +1,7 @@
package io.vertx.example.mail;
-import io.vertx.core.AbstractVerticle;
+import io.vertx.core.Future;
+import io.vertx.core.VerticleBase;
import io.vertx.ext.mail.MailClient;
import io.vertx.ext.mail.MailConfig;
import io.vertx.ext.mail.MailMessage;
@@ -17,20 +18,24 @@
*
* @author Alexander Lehmann
*/
-public class MailHeaders extends AbstractVerticle {
+public class MailHeaders extends VerticleBase {
// Convenience method so you can run it in your IDE
public static void main(String[] args) {
- VertxApplication.main(new String[]{MailHeaders.class.getName()});
- }
- public void start() {
// Start a local SMTP server, remove this line if you want to use your own server.
// It just prints the sent message to the console
LocalSmtpServer.start(2528);
+
+ VertxApplication.main(new String[]{MailHeaders.class.getName()});
+ }
+
+ private MailClient mailClient;
+
+ public Future> start() {
MailConfig mailConfig = new MailConfig().setHostname("localhost").setPort(2528);
- MailClient mailClient = MailClient.createShared(vertx, mailConfig);
+ mailClient = MailClient.createShared(vertx, mailConfig);
MailMessage email = new MailMessage()
.setFrom("user1@example.com")
@@ -42,16 +47,11 @@ public void start() {
.addHeader("Received", "from [192.168.1.1] by localhost")
.setText("This message should have a custom Message-ID");
- mailClient
+ return mailClient
.sendMail(email)
- .onComplete(result -> {
- if (result.succeeded()) {
- System.out.println(result.result());
+ .onSuccess(result -> {
+ System.out.println(result);
System.out.println("Mail sent");
- } else {
- System.out.println("got exception");
- result.cause().printStackTrace();
- }
});
}
diff --git a/mail-examples/src/main/java/io/vertx/example/mail/MailImages.java b/mail-examples/src/main/java/io/vertx/example/mail/MailImages.java
index 7c346d0dc..324750318 100644
--- a/mail-examples/src/main/java/io/vertx/example/mail/MailImages.java
+++ b/mail-examples/src/main/java/io/vertx/example/mail/MailImages.java
@@ -1,6 +1,7 @@
package io.vertx.example.mail;
-import io.vertx.core.AbstractVerticle;
+import io.vertx.core.Future;
+import io.vertx.core.VerticleBase;
import io.vertx.ext.mail.MailAttachment;
import io.vertx.ext.mail.MailClient;
import io.vertx.ext.mail.MailConfig;
@@ -15,19 +16,21 @@
*
* @author Alexander Lehmann
*/
-public class MailImages extends AbstractVerticle {
+public class MailImages extends VerticleBase {
public static void main(String[] args) {
- VertxApplication.main(new String[]{MailImages.class.getName()});
- }
-
- @Override
- public void start() {
// Start a local SMTP server, remove this line if you want to use your own server.
// It just prints the sent message to the console
LocalSmtpServer.start(2526);
- MailClient mailClient = MailClient.createShared(vertx, new MailConfig().setPort(2526));
+ VertxApplication.main(new String[]{MailImages.class.getName()});
+ }
+
+ private MailClient mailClient;
+
+ @Override
+ public Future> start() {
+ mailClient = MailClient.createShared(vertx, new MailConfig().setPort(2526));
MailMessage email = new MailMessage()
.setFrom("user@example.com (Sender)")
@@ -47,14 +50,11 @@ public void start() {
list.add(attachment);
email.setInlineAttachment(list);
- mailClient.sendMail(email).onComplete(result -> {
- if (result.succeeded()) {
- System.out.println(result.result());
- System.out.println("Mail sent");
- } else {
- System.out.println("got exception");
- result.cause().printStackTrace();
- }
+ return mailClient
+ .sendMail(email)
+ .onSuccess(result -> {
+ System.out.println(result);
+ System.out.println("Mail sent");
});
}
diff --git a/mail-examples/src/main/java/io/vertx/example/mail/MailLocalhost.java b/mail-examples/src/main/java/io/vertx/example/mail/MailLocalhost.java
index f50be7b87..d966515a5 100644
--- a/mail-examples/src/main/java/io/vertx/example/mail/MailLocalhost.java
+++ b/mail-examples/src/main/java/io/vertx/example/mail/MailLocalhost.java
@@ -1,6 +1,7 @@
package io.vertx.example.mail;
-import io.vertx.core.AbstractVerticle;
+import io.vertx.core.Future;
+import io.vertx.core.VerticleBase;
import io.vertx.ext.mail.MailClient;
import io.vertx.ext.mail.MailConfig;
import io.vertx.ext.mail.MailMessage;
@@ -13,19 +14,21 @@
*
* @author Alexander Lehmann
*/
-public class MailLocalhost extends AbstractVerticle {
+public class MailLocalhost extends VerticleBase {
public static void main(String[] args) {
- VertxApplication.main(new String[]{MailLocalhost.class.getName()});
- }
-
- @Override
- public void start() {
// Start a local SMTP server, remove this line if you want to use your own server.
// It just prints the sent message to the console
LocalSmtpServer.start(2525);
- MailClient mailClient = MailClient.createShared(vertx, new MailConfig().setPort(2525));
+ VertxApplication.main(new String[]{MailLocalhost.class.getName()});
+ }
+
+ private MailClient mailClient;
+
+ @Override
+ public Future> start() {
+ mailClient = MailClient.createShared(vertx, new MailConfig().setPort(2525));
MailMessage email = new MailMessage()
.setFrom("user@example.com (Sender)")
@@ -36,15 +39,12 @@ public void start() {
.setSubject("Test email")
.setText("this is a test email");
- mailClient.sendMail(email).onComplete(result -> {
- if (result.succeeded()) {
- System.out.println(result.result());
+ return mailClient
+ .sendMail(email)
+ .onSuccess(result -> {
+ System.out.println(result);
System.out.println("Mail sent");
- } else {
- System.out.println("got exception");
- result.cause().printStackTrace();
- }
- });
+ });
}
}
diff --git a/mail-examples/src/main/java/io/vertx/example/mail/MailLogin.java b/mail-examples/src/main/java/io/vertx/example/mail/MailLogin.java
index db804b89a..9f5c5c486 100644
--- a/mail-examples/src/main/java/io/vertx/example/mail/MailLogin.java
+++ b/mail-examples/src/main/java/io/vertx/example/mail/MailLogin.java
@@ -1,6 +1,7 @@
package io.vertx.example.mail;
-import io.vertx.core.AbstractVerticle;
+import io.vertx.core.Future;
+import io.vertx.core.VerticleBase;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.mail.*;
import io.vertx.launcher.application.VertxApplication;
@@ -15,18 +16,23 @@
*
* @author Alexander Lehmann
*/
-public class MailLogin extends AbstractVerticle {
+public class MailLogin extends VerticleBase {
public static void main(String[] args) {
+ // Start a local SMTP server, remove this line if you want to use your own server.
+ // It just prints the sent message to the console
+ LocalSmtpServer.startWithAuth(5870);
+
VertxApplication.main(new String[]{MailLogin.class.getName()});
}
- public void start() {
+ private MailClient mailClient;
+
+ public Future> start() {
// Start a local SMTP server, remove this line if you want to use your own server.
// It just prints the sent message to the console
LocalSmtpServer.startWithAuth(5870);
-
MailConfig mailConfig = new MailConfig()
.setHostname("localhost")
.setPort(5870)
@@ -36,7 +42,7 @@ public void start() {
.setUsername("username")
.setPassword("password");
- MailClient mailClient = MailClient.createShared(vertx, mailConfig);
+ mailClient = MailClient.createShared(vertx, mailConfig);
Buffer image = vertx.fileSystem().readFileBlocking("io/vertx/example/mail/logo-white-big.png");
@@ -61,17 +67,11 @@ public void start() {
email.setAttachment(list);
- mailClient
+ return mailClient
.sendMail(email)
- .onComplete(result -> {
- if (result.succeeded()) {
- System.out.println(result.result());
+ .onSuccess(result -> {
+ System.out.println(result);
System.out.println("Mail sent");
- } else {
- System.out.println("got exception");
- result.cause().printStackTrace();
- }
});
}
-
}