@Component(value="cuba_Emailer") public class Emailer extends java.lang.Object implements EmailerAPI
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Emailer.EmailSendTask |
protected static class |
Emailer.MessagePersistingContext |
| Modifier and Type | Field and Description |
|---|---|
protected Authentication |
authentication |
protected static java.lang.String |
BODY_FILE_EXTENSION |
protected java.util.concurrent.atomic.AtomicInteger |
callCount |
protected EmailerConfig |
config |
protected EmailSenderAPI |
emailSender |
protected FileStorageAPI |
fileStorage |
protected org.springframework.core.task.TaskExecutor |
mailSendTaskExecutor |
protected Metadata |
metadata |
protected Persistence |
persistence |
protected Resources |
resources |
protected TimeSource |
timeSource |
protected UserSessionSource |
userSessionSource |
NAME| Constructor and Description |
|---|
Emailer() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
applicationNotStartedYet() |
protected java.lang.String |
bodyTextFromByteArray(byte[] bodyContent) |
protected byte[] |
bodyTextToBytes(SendingMessage message) |
protected SendingMessage |
convertToSendingMessage(java.lang.String address,
java.lang.String from,
java.lang.String cc,
java.lang.String bcc,
java.lang.String caption,
java.lang.String body,
java.lang.String bodyContentType,
java.util.List<EmailHeader> headers,
EmailAttachment[] attachments,
java.lang.Integer attemptsCount,
java.util.Date deadline) |
protected FileDescriptor |
createAttachmentFileDescriptor(SendingAttachment attachment) |
protected FileDescriptor |
createBodyFileDescriptor(SendingMessage message,
byte[] bodyBytes) |
protected SendingMessage |
createClone(SendingMessage srcMessage) |
protected java.lang.String |
getContentBodyType(SendingMessage sendingMessage) |
protected java.lang.String |
getEmailerLogin() |
protected boolean |
isNeedToRetry(java.lang.Exception e) |
protected void |
loadBodyAndAttachments(SendingMessage message) |
java.lang.String |
loadContentText(SendingMessage sendingMessage)
Loads content text for given message.
|
protected java.util.List<SendingMessage> |
loadEmailsToSend() |
protected void |
markAsNonSent(SendingMessage sendingMessage) |
protected void |
markAsSent(SendingMessage sendingMessage) |
protected void |
migrateAttachment(EntityManager em,
SendingAttachment attachment) |
void |
migrateAttachmentsToFileStorage(java.util.List<SendingAttachment> attachments)
Migrate list of existing email attachments to be stored in file storage, in a single transaction.
|
void |
migrateEmailsToFileStorage(java.util.List<SendingMessage> messages)
Migrate list of existing messages to be stored in file storage, in a single transaction.
|
protected void |
migrateMessage(EntityManager em,
SendingMessage msg) |
protected void |
persistAndSendEmail(EmailInfo emailInfo) |
protected SendingMessage |
persistMessageIfPossible(SendingMessage sendingMessage) |
protected void |
persistMessages(java.util.List<SendingMessage> sendingMessageList,
SendingStatus status) |
protected void |
persistSendingMessage(EntityManager em,
SendingMessage message,
Emailer.MessagePersistingContext context) |
protected void |
prepareEmailInfo(EmailInfo emailInfo) |
protected void |
processBodyTemplate(EmailInfo info) |
java.lang.String |
processQueuedEmails()
Send emails added to the queue.
|
protected void |
removeOrphanFiles(Emailer.MessagePersistingContext context) |
protected void |
replaceRecipientIfNecessary(SendingMessage msg) |
protected void |
returnToQueue(SendingMessage sendingMessage) |
void |
sendEmail(EmailInfo info)
Send email synchronously.
|
void |
sendEmail(java.lang.String addresses,
java.lang.String caption,
java.lang.String body,
EmailAttachment... attachments)
Use
EmailerAPI.sendEmail(EmailInfo) instead. |
void |
sendEmail(java.lang.String addresses,
java.lang.String caption,
java.lang.String body,
java.lang.String bodyContentType,
EmailAttachment... attachments)
Use
EmailerAPI.sendEmail(EmailInfo) instead. |
java.util.List<SendingMessage> |
sendEmailAsync(EmailInfo info)
Send email asynchronously.
|
java.util.List<SendingMessage> |
sendEmailAsync(EmailInfo info,
java.lang.Integer attemptsCount,
java.util.Date deadline)
Send email asynchronously, with limited number of attempts.
|
protected java.lang.String |
sendQueuedEmails() |
protected void |
sendSendingMessage(SendingMessage sendingMessage) |
void |
setConfig(Configuration configuration) |
protected boolean |
shouldMarkNotSent(SendingMessage sendingMessage) |
protected java.util.List<SendingMessage> |
splitEmail(EmailInfo info,
java.lang.Integer attemptsCount,
java.util.Date deadline) |
protected void |
submitExecutorTask(SendingMessage msg) |
protected SendingAttachment |
toSendingAttachment(EmailAttachment ea) |
void |
updateSession()
Updates
Properties for JavaMail Session |
protected static final java.lang.String BODY_FILE_EXTENSION
protected EmailerConfig config
protected java.util.concurrent.atomic.AtomicInteger callCount
protected org.springframework.core.task.TaskExecutor mailSendTaskExecutor
@Inject protected UserSessionSource userSessionSource
@Inject protected TimeSource timeSource
@Inject protected Persistence persistence
@Inject protected Metadata metadata
@Inject protected Authentication authentication
@Inject protected EmailSenderAPI emailSender
@Inject protected Resources resources
@Inject protected FileStorageAPI fileStorage
@Inject public void setConfig(Configuration configuration)
protected java.lang.String getEmailerLogin()
public void sendEmail(java.lang.String addresses,
java.lang.String caption,
java.lang.String body,
EmailAttachment... attachments)
throws EmailException
EmailerAPIEmailerAPI.sendEmail(EmailInfo) instead.
Send email synchronously.
sendEmail in interface EmailerAPIaddresses - comma or semicolon separated list of addressescaption - email subjectbody - email bodyattachments - email attachmentsEmailException - in case of any errorspublic void sendEmail(java.lang.String addresses,
java.lang.String caption,
java.lang.String body,
java.lang.String bodyContentType,
EmailAttachment... attachments)
throws EmailException
EmailerAPIEmailerAPI.sendEmail(EmailInfo) instead.
Send email synchronously.
sendEmail in interface EmailerAPIaddresses - comma or semicolon separated list of addressescaption - email subjectbody - email bodybodyContentType - email body like "text/plain; charset=UTF-8" or "text/html; charset=UTF-8", etcattachments - email attachmentsEmailException - in case of any errorspublic void sendEmail(EmailInfo info) throws EmailException
EmailerAPIsendEmail in interface EmailerAPIinfo - email detailsEmailException - in case of any errorspublic java.util.List<SendingMessage> sendEmailAsync(EmailInfo info)
EmailerAPI
This method creates a list of SendingMessage instances, saves it to the database and returns immediately.
The actual sending is performed by the EmailerAPI.processQueuedEmails() method which should be invoked by a
scheduled task.
sendEmailAsync in interface EmailerAPIinfo - email detailsSendingMessagespublic java.util.List<SendingMessage> sendEmailAsync(EmailInfo info, java.lang.Integer attemptsCount, java.util.Date deadline)
EmailerAPIsendEmailAsync in interface EmailerAPIinfo - email detailsattemptsCount - count of attempts to send (1 attempt per scheduler tick). If not specified,
EmailerConfig.getDefaultSendingAttemptsCount() 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 to
SendingStatus.NOTSENTSendingMessagesprotected void prepareEmailInfo(EmailInfo emailInfo)
protected void processBodyTemplate(EmailInfo info)
protected java.util.List<SendingMessage> splitEmail(EmailInfo info, @Nullable java.lang.Integer attemptsCount, @Nullable java.util.Date deadline)
protected void sendSendingMessage(SendingMessage sendingMessage)
protected void persistAndSendEmail(EmailInfo emailInfo) throws EmailException
EmailException@Nullable protected SendingMessage persistMessageIfPossible(SendingMessage sendingMessage)
protected SendingMessage createClone(SendingMessage srcMessage)
public java.lang.String processQueuedEmails()
EmailerAPIThis method should be called periodically from a scheduled task.
processQueuedEmails in interface EmailerAPIprotected boolean applicationNotStartedYet()
protected java.lang.String sendQueuedEmails()
protected boolean shouldMarkNotSent(SendingMessage sendingMessage)
protected void submitExecutorTask(SendingMessage msg)
protected java.util.List<SendingMessage> loadEmailsToSend()
public java.lang.String loadContentText(SendingMessage sendingMessage)
EmailerAPIloadContentText in interface EmailerAPIpublic void updateSession()
EmailerAPIProperties for JavaMail SessionupdateSession in interface EmailerAPIprotected void loadBodyAndAttachments(SendingMessage message)
protected void persistMessages(java.util.List<SendingMessage> sendingMessageList, SendingStatus status)
protected void removeOrphanFiles(Emailer.MessagePersistingContext context)
protected void persistSendingMessage(EntityManager em, SendingMessage message, Emailer.MessagePersistingContext context) throws FileStorageException
FileStorageExceptionprotected FileDescriptor createAttachmentFileDescriptor(SendingAttachment attachment)
protected FileDescriptor createBodyFileDescriptor(SendingMessage message, byte[] bodyBytes)
protected void returnToQueue(SendingMessage sendingMessage)
protected void markAsSent(SendingMessage sendingMessage)
protected void markAsNonSent(SendingMessage sendingMessage)
protected SendingMessage convertToSendingMessage(java.lang.String address, java.lang.String from, java.lang.String cc, java.lang.String bcc, java.lang.String caption, java.lang.String body, java.lang.String bodyContentType, @Nullable java.util.List<EmailHeader> headers, @Nullable EmailAttachment[] attachments, @Nullable java.lang.Integer attemptsCount, @Nullable java.util.Date deadline)
protected java.lang.String getContentBodyType(SendingMessage sendingMessage)
protected void replaceRecipientIfNecessary(SendingMessage msg)
protected SendingAttachment toSendingAttachment(EmailAttachment ea)
protected byte[] bodyTextToBytes(SendingMessage message)
protected java.lang.String bodyTextFromByteArray(byte[] bodyContent)
protected boolean isNeedToRetry(java.lang.Exception e)
public void migrateEmailsToFileStorage(java.util.List<SendingMessage> messages)
EmailerAPImigrateEmailsToFileStorage in interface EmailerAPIpublic void migrateAttachmentsToFileStorage(java.util.List<SendingAttachment> attachments)
EmailerAPImigrateAttachmentsToFileStorage in interface EmailerAPIprotected void migrateMessage(EntityManager em, SendingMessage msg)
protected void migrateAttachment(EntityManager em, SendingAttachment attachment)