Skip to content
Snippets Groups Projects
process.js 1.17 KiB
Newer Older
S.Listl's avatar
S.Listl committed
import("system.datetime");
import("Sql_lib");
import("system.db");
import("system.util");
import("system.translate");
import("Bulkmail_lib");
import("system.vars");
import("system.notification");

var startTime = datetime.date();
var bulkMailId = vars.get("$local.bulkMailId");
var user = vars.get("$local.user");
S.Listl's avatar
S.Listl committed
var testRecipients = JSON.parse(vars.get("$local.testRecipients"));
var res = BulkMailUtils.sendBulkMail(bulkMailId, testRecipients);
S.Listl's avatar
S.Listl committed

S.Listl's avatar
S.Listl committed
if (user && !testRecipients)
S.Listl's avatar
S.Listl committed
{
    var mailName = newSelect("NAME")
                        .from("BULKMAIL")
                        .whereIfSet("BULKMAIL.BULKMAILID", bulkMailId)
                        .cell(true);
                        
S.Listl's avatar
S.Listl committed
    var message = translate.withArguments("Bulk mail \"%0\" was sent!", [mailName]);
    var description = translate.withArguments("%0 mails sent sucessfully, %1 mails failed. Process took %2 s.", 
        [res.sucessful, res.failed, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]);
    notification.addNotification(util.getNewUUID(), null, null, null, "BulkMailSent", null, notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description);
S.Listl's avatar
S.Listl committed
}