Interface EmailService

All Superinterfaces:
BaseService
All Known Implementing Classes:
DefaultEmailService

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

邮件服务接口,通过SMTP发送邮件。

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

此服务是可选的,需要在config.yml中配置。 模块在尝试发送邮件前应始终调用 isEnabled() 检查服务是否可用。

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

      检查邮件服务是否已启用并正确配置。

      模块必须在尝试发送邮件前调用此方法。 只有在以下条件满足时服务才被视为启用:

      • config.yml中的email.enable为true
      • SMTP主机、用户名和密码已配置
      Returns:
      true if email service is enabled and configured, false otherwise
      如果邮件服务已启用且配置正确则返回true,否则返回false
    • 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
      如果邮件发送成功则返回true,否则返回false
    • 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
      如果邮件成功发送给所有收件人则返回true,否则返回false
    • sendHtmlEmail

      boolean sendHtmlEmail(String to, String subject, String htmlContent)
      Send an HTML email.

      发送HTML邮件。

      Parameters:
      to - recipient email address
      收件人邮箱地址
      subject - email subject
      邮件主题
      htmlContent - email content (HTML format)
      邮件内容(HTML格式)
      Returns:
      true if email was sent successfully, false otherwise
      如果邮件发送成功则返回true,否则返回false
    • sendHtmlEmail

      boolean sendHtmlEmail(List<String> recipients, String subject, String htmlContent)
      Send an HTML email to multiple recipients.

      发送HTML邮件给多个收件人。

      Parameters:
      recipients - list of recipient email addresses
      收件人邮箱地址列表
      subject - email subject
      邮件主题
      htmlContent - email content (HTML format)
      邮件内容(HTML格式)
      Returns:
      true if email was sent successfully to all recipients, false otherwise
      如果邮件成功发送给所有收件人则返回true,否则返回false
    • 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
      异步任务,成功时返回true,否则返回false
    • sendHtmlEmailAsync

      CompletableFuture<Boolean> sendHtmlEmailAsync(String to, String subject, String htmlContent)
      Send an HTML email asynchronously.

      异步发送HTML邮件。

      Parameters:
      to - recipient email address
      收件人邮箱地址
      subject - email subject
      邮件主题
      htmlContent - email content (HTML format)
      邮件内容(HTML格式)
      Returns:
      CompletableFuture that completes with true if successful, false otherwise
      异步任务,成功时返回true,否则返回false
    • generateVerificationCode

      String generateVerificationCode(int length)
      Generate a random verification code.

      生成随机验证码。

      Parameters:
      length - length of the verification code (4-10 recommended)
      验证码长度(推荐4-10)
      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)
      验证码长度(推荐4-10)
      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
      如果邮件发送成功则返回true,否则返回false
    • 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
      异步任务,成功时返回true,否则返回false
    • testConnection

      boolean testConnection()
      Test the SMTP connection with current configuration.

      使用当前配置测试SMTP连接。

      Returns:
      true if connection is successful, false otherwise
      如果连接成功则返回true,否则返回false
    • getLastError

      String getLastError()
      Get the last error message if any operation failed.

      获取上次操作失败的错误信息。

      Returns:
      last error message or null if no error
      上次错误信息,如果没有错误则返回null