public class MailerService extends Object implements IMailerService
Modifier and Type | Field and Description |
---|---|
protected EmailDispatcher |
emailDispatcher |
protected int |
numEmailsPerBatch |
protected Long |
sendLimitDurationUnit |
protected Integer |
serverMailLimitPerLongDuration |
protected long |
tempDelayBetweenBatches |
Constructor and Description |
---|
MailerService() |
Modifier and Type | Method and Description |
---|---|
static EmailMessage |
constructEmailMessageFromTemplate(EmailMessage templateMessage,
List<EmailMultiPartBuilder.Part> emailContentParts)
A convenience Util that creates an
EmailMessage from some basic info. |
static EmailMessage |
constructEmailMessageFromTemplate(EmailMessage templateMessage,
String content)
Send single body plain text/html email.
Refers to DisposableMessage.getContentType() ; if null then checks EmailMessage.isAllowHtml() |
static EmailMessage |
constructEmailMessageFromTemplate(EmailMultiPartBuilder.Part.MultiPartType multiPartType,
ContentType contentType,
EmailMessage templateMessage,
List<EmailMultiPartBuilder.Part> emailContentParts)
A convenience Util that creates an
EmailMessage from some basic info |
static String |
deriveAttachmentId(EmailMultiPartBuilder.FilePart filepart,
String attachmentSuffix)
Some
EmailMultiPartBuilder.Part s may need to refer to EmailMultiPartBuilder.FilePart or EmailMultiPartBuilder.ImagePart . |
EmailDispatcher |
getEmailDispatcher() |
int |
getNumEmailsPerBatch()
For a given set of Recipients, how many will be clubbed in one batch
|
Long |
getSendLimitDurationUnit()
serverMailLimitPerLongDuration is the number of Mails that can be sent in a UNIT of time. |
Integer |
getServerMailLimitPerLongDuration()
Number of mails that can be sent in
sendLimitDurationUnit of time |
long |
getTempDelayBetweenBatches()
During bulk mailing operations, what is the delay in milli-secs between any 2 consequitive batches
|
protected void |
onBatchEnd(int batchNumber,
List<javax.mail.internet.InternetAddress> batch)
After a batch is dispatched and any waits are oever
|
protected void |
onBatchException(int batchNumber,
List<javax.mail.internet.InternetAddress> batch,
Exception e)
While batch processing if there is any Exception
|
protected void |
onBatchStart(int batchNumber,
List<javax.mail.internet.InternetAddress> batch)
Before a batch is dispatched
|
protected void |
onMailSend(int batchNumber,
List<javax.mail.internet.InternetAddress> batch,
long totalMailsSentTillNow)
Just after a batch is dispatched
|
void |
sendMail(EmailMessage message)
Send mails directly and synchronously
|
void |
sendMailBuffered(EmailMessage message)
Send the mail to
DisposableMessage.getRecipients() in a Buffered manner using a BufferSplitter . |
void |
setEmailDispatcher(EmailDispatcher emailDispatcher) |
void |
setNumEmailsPerBatch(int numEmailsPerBatch)
For a given set of Recipients, how many will be clubbed in one batch
|
void |
setSendLimitDurationUnit(Long sendLimitDurationUnit)
serverMailLimitPerLongDuration is the number of Mails that can be sent in a UNIT of time. |
void |
setServerMailLimitPerLongDuration(Integer serverMailLimitPerLongDuration)
Number of mails that can be sent in
sendLimitDurationUnit of time |
void |
setTempDelayBetweenBatches(long tempDelayBetweenBatches)
During bulk mailing operations, what is the delay in milli-secs between any 2 consequitive batches
|
@Autowired @Qualifier(value="DefaultEmailDispatcher") protected EmailDispatcher emailDispatcher
protected long tempDelayBetweenBatches
protected int numEmailsPerBatch
protected Long sendLimitDurationUnit
protected Integer serverMailLimitPerLongDuration
public static final String deriveAttachmentId(EmailMultiPartBuilder.FilePart filepart, String attachmentSuffix)
EmailMultiPartBuilder.Part
s may need to refer to EmailMultiPartBuilder.FilePart
or EmailMultiPartBuilder.ImagePart
. This can be done on the basis of a unique Id.
Additionally, the id must follow the convention to be unique and like "@xyz" convention, supplied by the suffix.filepart
- as EmailMultiPartBuilder.FilePart
attachmentSuffix
- as Stringpublic static EmailMessage constructEmailMessageFromTemplate(EmailMultiPartBuilder.Part.MultiPartType multiPartType, ContentType contentType, EmailMessage templateMessage, List<EmailMultiPartBuilder.Part> emailContentParts) throws Exception
EmailMessage
from some basic infomultiPartType
- as EmailMultiPartBuilder.Part.MultiPartType
contentType
- as ContentType
templateMessage
- as EmailMessage template for the message to be generatedemailContentParts
- as List of EmailMultiPartBuilder.Part
. Based on attachment flags, a EmailMultiPartBuilder.Part
maybe Attached or embedded.Exception
public static EmailMessage constructEmailMessageFromTemplate(EmailMessage templateMessage, List<EmailMultiPartBuilder.Part> emailContentParts) throws Exception
EmailMessage
from some basic info.
EmailMultiPartBuilder.Part.MultiPartType.parallel
, ContentType.MULTIPART_MIXED
templateMessage
- as EmailMessage template for the message to be generatedemailContentParts
- as List of EmailMultiPartBuilder.Part
. Based on attachment flags, a EmailMultiPartBuilder.Part
maybe Attached or embedded.Exception
public static EmailMessage constructEmailMessageFromTemplate(EmailMessage templateMessage, String content) throws Exception
DisposableMessage.getContentType()
; if null then checks EmailMessage.isAllowHtml()
templateMessage
- as EmailMessage template for the message to be generatedcontent
- Exception
public void sendMail(EmailMessage message) throws Exception
IMailerService
sendMail
in interface IMailerService
Exception
public void sendMailBuffered(EmailMessage message) throws Exception
DisposableMessage.getRecipients()
in a Buffered manner using a BufferSplitter
. The process may be synchronours or asynchronous;
but in both cases Exceptions during batch processing will be notified to onBatchException(int, List, Exception)
and not thrown directly.
Reader
like CSVMailAddressReader
.
List emailAddresses = CSVMailAddressReader_Instance.read(new File(userAddressListCSVPath));
EmailMessage.getCCList()
and EmailMessage.getBCCList()
to the main Recipient listsendMailBuffered
in interface IMailerService
Exception
protected void onBatchStart(int batchNumber, List<javax.mail.internet.InternetAddress> batch)
batchNumber,
- index of the batch. Starts from 0batch
- as List of InternetAddress
in this batchprotected void onMailSend(int batchNumber, List<javax.mail.internet.InternetAddress> batch, long totalMailsSentTillNow)
batchNumber,
- index of the batch. Starts from 0batch
- as List of InternetAddress
in this batchtotalMailsSentTillNow
- as longprotected void onBatchEnd(int batchNumber, List<javax.mail.internet.InternetAddress> batch)
batchNumber,
- index of the batch. Starts from 0batch
- as List of InternetAddress
in this batchprotected void onBatchException(int batchNumber, List<javax.mail.internet.InternetAddress> batch, Exception e)
batchNumber,
- index of the batch. Starts from 0batch
- as List of InternetAddress
in this batche
- as Exceptionpublic EmailDispatcher getEmailDispatcher()
public void setEmailDispatcher(EmailDispatcher emailDispatcher)
public long getTempDelayBetweenBatches()
public void setTempDelayBetweenBatches(long tempDelayBetweenBatches)
public int getNumEmailsPerBatch()
public void setNumEmailsPerBatch(int numEmailsPerBatch)
public Long getSendLimitDurationUnit()
serverMailLimitPerLongDuration
is the number of Mails that can be sent in a UNIT of time.
The UNIT of time (milli secs definining One unit) is determined by this attribute
public void setSendLimitDurationUnit(Long sendLimitDurationUnit)
serverMailLimitPerLongDuration
is the number of Mails that can be sent in a UNIT of time.
The UNIT of time (milli secs definining One unit) is determined by this attribute
public Integer getServerMailLimitPerLongDuration()
sendLimitDurationUnit
of timepublic void setServerMailLimitPerLongDuration(Integer serverMailLimitPerLongDuration)
sendLimitDurationUnit
of timeCopyright © 2018. All rights reserved.