Mail Resender
Last modified by Mark Kohlmann on 2024/12/20 05:47
- Mail Resender
-
Resend emails that were prepared but that were either not sent or that failed to be sent (i.e. all mails in the "prepare_success" state). The mails are resent synchronously one by one to avoid requiring a lot of memory in case a lot of emails need to be resent.
- 0 0 12 * * ?
- The script is the code that will be executed when the job is triggered by the scheduler. It should be written in the Groovy language. The XWiki API is available through the xwiki and context pre-defined variables.
- import org.apache.commons.lang3.exception.ExceptionUtils
services.mail.storage.resend(['state' : 'prepare_success'], 0, 0)
if (services.mail.sender.lastError) {
// Send a mail to the administrator with the exception, using the default "from" for both
// the sender and the recipient. If no default from is used then don't send anything.
def from = services.mail.sender.configuration.fromAddress
if (from) {
def message = services.mail.sender.createMessage(from, from, 'Mail Resender Scheduler Job Failed')
message.addPart('text/plain', """
The following error happened when trying to resend emails:
${ExceptionUtils.getMessage(services.mail.sender.lastError)}
""")
}
}