Class MailSenderService

java.lang.Object
com.serinity.accesscontrol.service.MailSenderService

public final class MailSenderService extends Object
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:

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 Details

    • send

      public static final void send(String toEmail, String subject, String htmlText)
      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

      public static final void sendPasswordReset(String username, String toEmail, String generatedCode)
      Load HTML template from ResourceFile enum
      Parameters:
      username - the name of the recipient to personalize the template
      toEmail - the recipient's email address
      generatedCode - a code or token to insert into the template