МетаЭра

Mail Resender

Редактировал(а) Вячеслав Мясоед 2024-08-16 11:53

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 * * ?
Скрипт содержит код, который будет выполнен во время запуска задания планировщиком. Он должен быть написан на языке Groovy. Доступ к API XWiki осуществляется посредством предопределенных переменных *xwiki* и *context*.
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)}
    """
)
 }
}

Назад к списку заданий