-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to handle success/failure in async mode (including testConnection()) #148
Comments
Hmm, Simple Java Mail uses JDK 1.7, so it would need to be something else. Any preference? Also, this issue will be solved another way with #121 when you can add custom steps in between the various stages of emailing (including handling exceptions). However, that won't be in the near future. |
I've added
You can also implement your own (threaded) checking routine that checks Would this suit your needs? |
Hi, thanks for the reply! Would it be possible to provide a basic interface interface MailCallback {
void onSuccess();
void onFailure(Exception e);
} which the user can implement and pass into |
…dition to Future. Also made testConnection support the async flag similarly
You got your wish @trathschlag! Both sending emails and testing server connections can now be done asynchronously with either Future or Handlers. Using HandlersAsyncResponse asyncResponse = mailer.sendMail(email, true);
// or: mailer.testConnection(email, true);
asyncResponse.onSuccess(() -> System.out.println("Success"));
asyncResponse.onException((e) -> System.err.println("error")); Using FutureFuture<?> f = asyncResponse.getFuture();
// f.get() actually blocks until done, below is an example custom loop
// for checking result in a non-blocking way:
while (!f.isDone()) Thread.sleep(100);
// result is in, check it
try {
f.get(); // without the above loop, this would actually block until done
System.err.println("success");
} catch (ExecutionException e) {
System.err.println("error");
} |
Released in 6.0.0-rc1!! |
6.0.0 has released as well, finally. |
Hi!
It would be really useful if you could somehow handle success and failures when sending asynchronously. Is it be possible to implement CompletableFuture as a return value for
mailer.sendAsync(...)
or something?I am interested to prepare a pull request.
Thanks in advance!
The text was updated successfully, but these errors were encountered: