Mail Resender

Version 36.1 von Borys Sobieski am 2025/02/21 07: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 * * ?
Das Skript ist der Code der ausgeführt wird, wenn der Job durch die Job-Steuerung gestartet wird. Der Code sollte in groovy geschrieben werden. Die XWiki-API ist über die vorgegebenen Variablen *xwiki* und *context* verfügbar.
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)}
    """
)
 }
}

Zurück zur Jobliste