22.214.171.124. Sending Methods
To send an email, the
EmailerAPI bean should be used at the Middleware, and the
EmailService service – at the client tier.
The basic methods of these components are described below:
sendEmail()– synchronous message sending. The calling code is blocked while sending the message to the SMTP server.
The message can be transmitted in the form of a set of parameters (the comma-separated list of recipients, subject, content, array of attachments), and in the form of a special
EmailInfoobject, which encapsulates all this information and allows you to explicitly set the sender’s address and to form the message body using a FreeMarker template.
EmailExceptionmay be thrown during synchronous sending, containing the information on the recipient addresses, where delivery has failed, and the corresponding error messages.
During the execution of the method, a
SendingMessageinstance is created in the database for each recipient. It has the initial
SendingStatus.SENTafter successful sending. In case of a message sending error, the message status changes to
sendEmailAsync()– asynchronous message sending. This method returns the list (by the number of recipients) of
SendingStatus.QUEUEstatus, which were created in the database. The actual sending is performed with the subsequent call of the
EmailerAPI.processQueuedEmails()method, which should be invoked from a scheduled task with the desired frequency.