Package io.jmix.email
Interface Emailer
- All Known Implementing Classes:
EmailerImpl
public interface Emailer
Provides application with emailing functionality.
Sending email can be synchronous (caller's thread is blocked until email is delivered to SMTP server) or asynchronous (email is persisted in a DB queue and sent later by scheduled task).
In order to send emails asynchronously, you should register a scheduled task that periodically invokes
Sending email can be synchronous (caller's thread is blocked until email is delivered to SMTP server) or asynchronous (email is persisted in a DB queue and sent later by scheduled task).
In order to send emails asynchronously, you should register a scheduled task that periodically invokes
processQueuedEmails()
method.-
Method Summary
Modifier and TypeMethodDescriptionSend emails added to the queue.void
Send email synchronously.void
sendEmail
(String address, String subject, String body, String bodyContentType, Boolean important, EmailAttachment... attachment) Send email synchronously.sendEmailAsync
(EmailInfo info) Send email asynchronously.sendEmailAsync
(EmailInfo info, Integer attemptsLimit, Date deadline) Send email asynchronously, with limited number of attempts.
-
Method Details
-
sendEmail
void sendEmail(String address, String subject, String body, String bodyContentType, Boolean important, EmailAttachment... attachment) throws EmailException Send email synchronously.- Parameters:
address
- comma or semicolon separated list of addressessubject
- email subjectbody
- email bodybodyContentType
- email body like "text/plain; charset=UTF-8" or "text/html; charset=UTF-8", etcattachment
- email attachments- Throws:
EmailException
- in case of any errors
-
sendEmail
Send email synchronously.- Parameters:
info
- email details- Throws:
EmailException
- in case of any errors
-
sendEmailAsync
SendingMessage sendEmailAsync(EmailInfo info, @Nullable Integer attemptsLimit, @Nullable Date deadline) Send email asynchronously, with limited number of attempts.- Parameters:
info
- email detailsattemptsLimit
- count of attempts to send (1 attempt per scheduler tick). If not specified,EmailerProperties.getDefaultSendingAttemptsLimit()
is useddeadline
- Emailer tries to send message till deadline. If deadline has come and message has not been sent, status of this message is changed toSendingStatus.NOT_SENT
- Returns:
- created
SendingMessage
-
sendEmailAsync
Send email asynchronously.This method creates a
SendingMessage
, saves it to the database and returns immediately. The actual sending is performed by theprocessQueuedEmails()
method which should be invoked by a scheduled task.- Parameters:
info
- email details- Returns:
- created
SendingMessage
-
processQueuedEmails
String processQueuedEmails()Send emails added to the queue.This method should be called periodically from a scheduled task.
- Returns:
- short message describing how many emails were sent, or error message
-