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 processQueuedEmails() method.
  • 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 addresses
      subject - email subject
      body - email body
      bodyContentType - email body like "text/plain; charset=UTF-8" or "text/html; charset=UTF-8", etc
      attachment - email attachments
      Throws:
      EmailException - in case of any errors
    • sendEmail

      void sendEmail(EmailInfo info) throws EmailException
      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 details
      attemptsLimit - count of attempts to send (1 attempt per scheduler tick). If not specified, EmailerProperties.getDefaultSendingAttemptsLimit() is used
      deadline - Emailer tries to send message till deadline. If deadline has come and message has not been sent, status of this message is changed to SendingStatus.NOT_SENT
      Returns:
      created SendingMessage
    • sendEmailAsync

      SendingMessage sendEmailAsync(EmailInfo info)
      Send email asynchronously.

      This method creates a SendingMessage, saves it to the database and returns immediately. The actual sending is performed by the processQueuedEmails() 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