simple-java-mail icon indicating copy to clipboard operation
simple-java-mail copied to clipboard

Email not sending when using asynchronous feature

Open akirupa opened this issue 3 years ago • 6 comments

When using mailer.sendMail(email, /* async = */ true); or Mailer mailer = mailerBuilder.(..).async().buildMailer(); to send async emails it seems to send no emails when tested and there seems to be no errors that are indicated when testing too. When I send a normal email that is not async it seems to send no problem so Im not sure why the async email is not able to send. https://www.simplejavamail.org/features.html#section-sending-asynchronously

akirupa avatar Jul 29 '22 15:07 akirupa

This is one of the most used features so I'm a little skeptical, but let's see. Which version are you on? You can take the result of sendMail() and handle it's async result, have you tried that? Also, are you catching and swallowing any exception by chance?

bbottema avatar Jul 29 '22 15:07 bbottema

Im on version 7.1.0. I am not catching any exceptions at the moment.

akirupa avatar Jul 29 '22 16:07 akirupa

So what do you get when you configure a result handler, like so:

mailer.sendMail(email, true)
	.whenComplete((result, ex) -> {
		if (ex != null) {
			System.err.printf("Execution failed %s", ex);
		} else {
			System.err.printf("Execution completed: %s", result);
		}
	});

bbottema avatar Jul 29 '22 17:07 bbottema

when i configure the handler like that it gets neither execution failed nor complete. When i get rid of the true for sendmail to make it sync it says execution completed null for some reason

akirupa avatar Jul 29 '22 17:07 akirupa

Do you have logging enabled? If you add something like logback/log4j2 to your test, you can see what Simple Java Mail is doing. See here for more details on this.

bbottema avatar Jul 29 '22 22:07 bbottema

i did add log4j2 to my test but it seems to still not output anything, the ex exception seems to be empty rather than null

akirupa avatar Aug 02 '22 14:08 akirupa

I'm not sure where to go from here. You report one of the core and most used features is not working, you don't have errors and you don't have relevant logging. That's not much to go on. Closing until I'm convinced this is not a user error.

bbottema avatar Jan 13 '23 14:01 bbottema