use of org.xwiki.mail.ExtendedMimeMessage in project xwiki-platform by xwiki.
the class SendMailRunnable method sendMail.
/**
* Send the mail.
*
* @param item the queue item containing all the data for sending the mail
*/
protected void sendMail(SendMailQueueItem item) {
prepareContextForQueueItem(item);
MailListener listener = item.getListener();
ExtendedMimeMessage message;
try {
// Step 1: Load the message from the filesystem store
message = this.mailContentStore.load(item.getSession(), item.getBatchId(), item.getUniqueMessageId());
} catch (Exception e) {
if (listener != null) {
listener.onSendMessageFatalError(item.getUniqueMessageId(), e, Collections.<String, Object>emptyMap());
}
return;
}
try {
// TODO: explain why!
if (item.getSession() != this.currentSession || (this.count % 100) == 0) {
closeTransport();
this.currentSession = item.getSession();
this.currentTransport = this.currentSession.getTransport("smtp");
this.currentTransport.connect();
} else if (!this.currentTransport.isConnected()) {
this.currentTransport.connect();
}
// Step 3: Send the mail
// Unlike the static send method, the sendMessage method does not call the saveChanges method on the
// message; this prevent the MessageID header to be changed.
this.currentTransport.sendMessage(message, message.getAllRecipients());
this.count++;
// Step 4: Notify the user of the success if a listener has been provided
if (listener != null) {
listener.onSendMessageSuccess(message, Collections.<String, Object>emptyMap());
}
} catch (Exception e) {
// An error occurred, notify the user if a listener has been provided.
if (listener != null) {
listener.onSendMessageError(message, e, Collections.<String, Object>emptyMap());
}
}
}
Aggregations