Class EmailerImpl

java.lang.Object
io.jmix.email.impl.EmailerImpl
All Implemented Interfaces:
Emailer

@Component("email_Emailer") public class EmailerImpl extends Object implements Emailer
  • Field Details

    • emailerProperties

      @Autowired protected EmailerProperties emailerProperties
    • callCount

      protected AtomicInteger callCount
    • emailDataProvider

      @Autowired protected EmailDataProvider emailDataProvider
    • metadata

      @Autowired protected Metadata metadata
    • authenticator

      @Autowired protected SystemAuthenticator authenticator
    • emailSender

      @Autowired protected EmailSender emailSender
    • metadataTools

      @Autowired protected MetadataTools metadataTools
    • applicationContext

      @Autowired protected org.springframework.context.ApplicationContext applicationContext
    • emailCleaner

      @Autowired protected EmailCleaner emailCleaner
    • meterRegistry

      @Autowired protected io.micrometer.core.instrument.MeterRegistry meterRegistry
    • mailSendTaskExecutor

      protected org.springframework.core.task.TaskExecutor mailSendTaskExecutor
  • Constructor Details

    • EmailerImpl

      public EmailerImpl()
  • Method Details

    • initMailSendTaskExecutor

      @PostConstruct protected void initMailSendTaskExecutor()
    • destroyMailSendTaskExecutor

      @PreDestroy protected void destroyMailSendTaskExecutor() throws Exception
      Throws:
      Exception
    • sendEmail

      public void sendEmail(String address, String subject, String body, String bodyContentType, Boolean important, EmailAttachment... attachment) throws EmailException
      Description copied from interface: Emailer
      Send email synchronously.
      Specified by:
      sendEmail in interface Emailer
      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

      public void sendEmail(EmailInfo info) throws EmailException
      Description copied from interface: Emailer
      Send email synchronously.
      Specified by:
      sendEmail in interface Emailer
      Parameters:
      info - email details
      Throws:
      EmailException - in case of any errors
    • sendEmailAsync

      public SendingMessage sendEmailAsync(EmailInfo info)
      Description copied from interface: Emailer
      Send email asynchronously.

      This method creates a SendingMessage, saves it to the database and returns immediately. The actual sending is performed by the Emailer.processQueuedEmails() method which should be invoked by a scheduled task.

      Specified by:
      sendEmailAsync in interface Emailer
      Parameters:
      info - email details
      Returns:
      created SendingMessage
    • sendEmailAsync

      public SendingMessage sendEmailAsync(EmailInfo info, @Nullable Integer attemptsLimit, @Nullable Date deadline)
      Description copied from interface: Emailer
      Send email asynchronously, with limited number of attempts.
      Specified by:
      sendEmailAsync in interface Emailer
      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
    • prepareEmailInfo

      protected void prepareEmailInfo(EmailInfo emailInfo)
    • convertToSendingMessage

      protected SendingMessage convertToSendingMessage(EmailInfo info, @Nullable Integer attemptsLimit, @Nullable Date deadline)
    • sendSendingMessage

      protected void sendSendingMessage(SendingMessage sendingMessage)
    • persistAndSendEmail

      protected void persistAndSendEmail(EmailInfo emailInfo) throws EmailException
      Throws:
      EmailException
    • persistMessageIfPossible

      protected @Nullable SendingMessage persistMessageIfPossible(SendingMessage sendingMessage)
    • createClone

      protected SendingMessage createClone(SendingMessage srcMessage)
    • processQueuedEmails

      public String processQueuedEmails()
      Description copied from interface: Emailer
      Send emails added to the queue.

      This method should be called periodically from a scheduled task.

      Specified by:
      processQueuedEmails in interface Emailer
      Returns:
      short message describing how many emails were sent, or error message
    • sendQueuedEmails

      protected String sendQueuedEmails()
    • submitExecutorTask

      protected void submitExecutorTask(SendingMessage msg)
    • getContentBodyType

      protected String getContentBodyType(SendingMessage sendingMessage)
    • replaceRecipientIfNecessary

      protected void replaceRecipientIfNecessary(SendingMessage msg)
    • createMailSendTaskExecutor

      protected org.springframework.core.task.TaskExecutor createMailSendTaskExecutor()
    • bindMailSendTaskExecutorMetrics

      protected void bindMailSendTaskExecutorMetrics()
    • toSendingAttachment

      protected SendingAttachment toSendingAttachment(EmailAttachment ea)
    • isNeedToRetry

      protected boolean isNeedToRetry(Exception e)