2424import java .util .Properties ;
2525import java .util .concurrent .ExecutorService ;
2626import java .util .concurrent .Executors ;
27+ import java .util .concurrent .Future ;
2728import java .util .concurrent .Phaser ;
2829
2930import static java .lang .String .format ;
@@ -177,10 +178,11 @@ private static AnonymousSocks5Server configureSessionWithProxy(@Nonnull final Pr
177178 * @param email The information for the email to be sent.
178179 * @param async If false, this method blocks until the mail has been processed completely by the SMTP server. If true, a new thread is started to
179180 * send the email and this method returns immediately.
181+ * @return A {@link Future} or null if not <em>async</em>.
180182 * @throws MailException Can be thrown if an email isn't validating correctly, or some other problem occurs during connection, sending etc.
181183 * @see Executors#newFixedThreadPool(int)
182184 */
183- public final synchronized void send (final Email email , final boolean async ) {
185+ public final synchronized Future <?> send (final Email email , final boolean async ) {
184186 /*
185187 we need to track even non-async emails to prevent async emails from shutting down
186188 the proxy bridge server (or connection pool in async mode) while a non-async email is still being processed
@@ -196,7 +198,7 @@ the proxy bridge server (or connection pool in async mode) while a non-async ema
196198 executor = Executors .newFixedThreadPool (operationalConfig .getThreadPoolSize ());
197199 }
198200 configureSessionWithTimeout (session , operationalConfig .getSessionTimeout ());
199- executor .execute (new Runnable () {
201+ return executor .submit (new Runnable () {
200202 @ Override
201203 public void run () {
202204 sendMailClosure (session , email );
@@ -209,6 +211,7 @@ public String toString() {
209211 });
210212 } else {
211213 sendMailClosure (session , email );
214+ return null ;
212215 }
213216 }
214217
0 commit comments