Class MailSenderService
java.lang.Object
com.serinity.accesscontrol.service.MailSenderService
Utility service responsible for sending emails using SMTP.
This class provides a centralized method for sending HTML emails through an
SMTP server configured via environment variables loaded by
EnvironmentVariableLoader.
The class uses the Mailer library to construct and send emails with the specified subject, HTML content, and recipient.
The SMTP server, port, username, and authentication token are retrieved from environment variables. If the email cannot be sent due to an SMTP or mail-related exception, it is caught and printed to the console.
Exposed functionality:
send(String, String, String)– Sends an HTML email to a specified recipient.
Example usage:
MailSenderService.send(
"zouariomar20@gmail.com",
"Welcome!",
"Hello World");
Exceptions:
com.icegreen.greenmail.util.MailException- Caught internally and printed if the email cannot be sent.
SMTP configuration must be correctly set in environment variables; otherwise, email sending will fail.
- Since:
- 2026-02-16
- Version:
- 1.0
- Author:
- @ZouariOmar (zouariomar20@gmail.com)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic final voidSends an HTML email to a specific recipient using SMTP configuration loaded from environment variables.static final voidsendPasswordReset(String username, String toEmail, String generatedCode) Load HTML template from ResourceFile enum
-
Method Details
-
send
Sends an HTML email to a specific recipient using SMTP configuration loaded from environment variables.- Parameters:
toEmail- The recipient's email address.subject- The subject line of the email.htmlText- The HTML content of the email.
-
sendPasswordReset
Load HTML template from ResourceFile enum- Parameters:
username- the name of the recipient to personalize the templatetoEmail- the recipient's email addressgeneratedCode- a code or token to insert into the template
-