Interface EmailService

All Superinterfaces:
BaseService
All Known Implementing Classes:
DefaultEmailService

public interface EmailService extends BaseService
Email service interface for sending emails via SMTP.

This service is optional and must be configured in config.yml. Modules should always call isEnabled() before attempting to send emails.

Since:
6.2.0
Version:
1.0.0
Author:
wisdomme
  • Method Details

    • isEnabled

      boolean isEnabled()
      Check if the email service is enabled and properly configured.

      Modules MUST call this method before attempting to send emails. The service is considered enabled only when:

      • email.enable is true in config.yml
      • SMTP host, username, and password are configured
      Returns:
      true if email service is enabled and configured, false otherwise
    • sendEmail

      boolean sendEmail(String to, String subject, String content)
      Send a plain text email.
      Parameters:
      to - recipient email address
      subject - email subject
      content - email content (plain text)
      Returns:
      true if email was sent successfully, false otherwise
    • sendEmail

      boolean sendEmail(List<String> recipients, String subject, String content)
      Send a plain text email to multiple recipients.
      Parameters:
      recipients - list of recipient email addresses
      subject - email subject
      content - email content (plain text)
      Returns:
      true if email was sent successfully to all recipients, false otherwise
    • sendHtmlEmail

      boolean sendHtmlEmail(String to, String subject, String htmlContent)
      Send an HTML email.
      Parameters:
      to - recipient email address
      subject - email subject
      htmlContent - email content (HTML format)
      Returns:
      true if email was sent successfully, false otherwise
    • sendHtmlEmail

      boolean sendHtmlEmail(List<String> recipients, String subject, String htmlContent)
      Send an HTML email to multiple recipients.
      Parameters:
      recipients - list of recipient email addresses
      subject - email subject
      htmlContent - email content (HTML format)
      Returns:
      true if email was sent successfully to all recipients, false otherwise
    • sendEmailAsync

      CompletableFuture<Boolean> sendEmailAsync(String to, String subject, String content)
      Send a plain text email asynchronously.
      Parameters:
      to - recipient email address
      subject - email subject
      content - email content (plain text)
      Returns:
      CompletableFuture that completes with true if successful, false otherwise
    • sendHtmlEmailAsync

      CompletableFuture<Boolean> sendHtmlEmailAsync(String to, String subject, String htmlContent)
      Send an HTML email asynchronously.
      Parameters:
      to - recipient email address
      subject - email subject
      htmlContent - email content (HTML format)
      Returns:
      CompletableFuture that completes with true if successful, false otherwise
    • generateVerificationCode

      String generateVerificationCode(int length)
      Generate a random verification code.
      Parameters:
      length - length of the verification code (4-10 recommended)
      Returns:
      random numeric verification code
    • generateAlphanumericCode

      String generateAlphanumericCode(int length)
      Generate a random alphanumeric verification code.
      Parameters:
      length - length of the verification code (4-10 recommended)
      Returns:
      random alphanumeric verification code
    • sendVerificationCodeEmail

      boolean sendVerificationCodeEmail(String to, String verificationCode, String serverName, int expiryMinutes)
      Send a verification code email using a predefined template.
      Parameters:
      to - recipient email address
      verificationCode - the verification code to send
      serverName - server name to display in the email
      expiryMinutes - validity period in minutes
      Returns:
      true if email was sent successfully, false otherwise
    • sendVerificationCodeEmailAsync

      CompletableFuture<Boolean> sendVerificationCodeEmailAsync(String to, String verificationCode, String serverName, int expiryMinutes)
      Send a verification code email asynchronously.
      Parameters:
      to - recipient email address
      verificationCode - the verification code to send
      serverName - server name to display in the email
      expiryMinutes - validity period in minutes
      Returns:
      CompletableFuture that completes with true if successful, false otherwise
    • testConnection

      boolean testConnection()
      Test the SMTP connection with current configuration.
      Returns:
      true if connection is successful, false otherwise
    • getLastError

      String getLastError()
      Get the last error message if any operation failed.
      Returns:
      last error message or null if no error