[Minor] Send mail user challenge async

This commit is contained in:
Robert von Burg 2023-03-14 08:54:27 +01:00
parent 69e71384e6
commit cace8c5156
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 7 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package li.strolch.privilege.handler;
import static li.strolch.privilege.base.PrivilegeConstants.EMAIL;
import java.text.MessageFormat;
import java.util.concurrent.CompletableFuture;
import li.strolch.privilege.model.internal.User;
import li.strolch.utils.SmtpMailer;
@ -24,10 +25,13 @@ public class MailUserChallengeHandler extends UserChallengeHandler {
String text = sb.toString();
String recipient = user.getEmail();
if (StringHelper.isEmpty(recipient)) {
String msg = "User {0} has no property {1}";
throw new RuntimeException(MessageFormat.format(msg, user.getUsername(), EMAIL));
String msg = "User {0} has no property {1}, so can not initiate challenge!";
logger.error(MessageFormat.format(msg, user.getUsername(), EMAIL));
return;
}
SmtpMailer.getInstance().sendMail(subject, text, recipient);
// send e-mail async
CompletableFuture.runAsync(() -> SmtpMailer.getInstance().sendMail(subject, text, recipient))
.whenComplete((unused, throwable) -> logger.error("Failed to send e-mail for user " + user, throwable));
}
}