I have a scenario in which I need to send bulk emails to senders. I can send only 10 mails at a time. So I set all my mail contents in variable and then add only ten recipients at a time. Then after I send email, I again add ten next receipients to it.
private void addRecipients(Message pMessage, List pRecipients, Message.RecipientType pType, int pNum, int pOffset, int pBulkSize){
for (int i = 0; i < pRecipients.size(); i++) {
int offset = pNum + i;
if (pBulkSize != 0 && (offset < pOffset || offset >= pOffset + pBulkSize)) {
continue;
}
Address a;
Object r = pRecipients.get(i);
pMessage.addRecipient(pType, a);
}
But the problem is I am not able to remove the last ten receipients from the variable.
Transport.send(message);
After this line, my loop restarts and again the addRecipients method is called. But now the object
MimeMessage message = getIntialEmailConfiguration();
message has previous recipients as well.
I want to know how to reset that one property and remove existing recipients.
Use the Message.setRecipients which will remove and apply multiple addresses.
Your code example won't compile because 'Address a' is never assigned a value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With