Package com.ultikits.ultitools.services
Interface EmailService
- All Superinterfaces:
BaseService
- All Known Implementing Classes:
DefaultEmailService
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 Summary
Modifier and TypeMethodDescriptiongenerateAlphanumericCode(int length) Generate a random alphanumeric verification code.generateVerificationCode(int length) Generate a random verification code.Get the last error message if any operation failed.booleanCheck if the email service is enabled and properly configured.booleanSend a plain text email.booleanSend a plain text email to multiple recipients.sendEmailAsync(String to, String subject, String content) Send a plain text email asynchronously.booleansendHtmlEmail(String to, String subject, String htmlContent) Send an HTML email.booleansendHtmlEmail(List<String> recipients, String subject, String htmlContent) Send an HTML email to multiple recipients.sendHtmlEmailAsync(String to, String subject, String htmlContent) Send an HTML email asynchronously.booleansendVerificationCodeEmail(String to, String verificationCode, String serverName, int expiryMinutes) Send a verification code email using a predefined template.sendVerificationCodeEmailAsync(String to, String verificationCode, String serverName, int expiryMinutes) Send a verification code email asynchronously.booleanTest the SMTP connection with current configuration.Methods inherited from interface com.ultikits.ultitools.interfaces.BaseService
getAuthor, getName, getResourceFolderName, getVersion
-
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
Send a plain text email.- Parameters:
to- recipient email addresssubject- email subjectcontent- email content (plain text)- Returns:
- true if email was sent successfully, false otherwise
-
sendEmail
Send a plain text email to multiple recipients.- Parameters:
recipients- list of recipient email addressessubject- email subjectcontent- email content (plain text)- Returns:
- true if email was sent successfully to all recipients, false otherwise
-
sendHtmlEmail
Send an HTML email.- Parameters:
to- recipient email addresssubject- email subjecthtmlContent- email content (HTML format)- Returns:
- true if email was sent successfully, false otherwise
-
sendHtmlEmail
Send an HTML email to multiple recipients.- Parameters:
recipients- list of recipient email addressessubject- email subjecthtmlContent- email content (HTML format)- Returns:
- true if email was sent successfully to all recipients, false otherwise
-
sendEmailAsync
Send a plain text email asynchronously.- Parameters:
to- recipient email addresssubject- email subjectcontent- email content (plain text)- Returns:
- CompletableFuture that completes with true if successful, false otherwise
-
sendHtmlEmailAsync
Send an HTML email asynchronously.- Parameters:
to- recipient email addresssubject- email subjecthtmlContent- email content (HTML format)- Returns:
- CompletableFuture that completes with true if successful, false otherwise
-
generateVerificationCode
Generate a random verification code.- Parameters:
length- length of the verification code (4-10 recommended)- Returns:
- random numeric verification code
-
generateAlphanumericCode
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 addressverificationCode- the verification code to sendserverName- server name to display in the emailexpiryMinutes- 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 addressverificationCode- the verification code to sendserverName- server name to display in the emailexpiryMinutes- 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
-