Skip to content
Snippets Groups Projects
Commit 42114f49 authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Merge branch 'm_1086052_bulkmail_errorlogging' into '2021.1'

[Projekt: xRM-Marketing][TicketNr.: 1086052][Absturz des Mailversands bei ungültigen Mailadressen.]

See merge request xrm/basic!1208
parents 55274249 1fb5c831
No related branches found
No related tags found
No related merge requests found
......@@ -192,6 +192,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
{
let isSuccess = false;
let bouncedStatus = null;
var errorMessage = "";
let recipientId = recipient["BULKMAILRECIPIENTID"];
let contactId = recipient["CONTACT_ID"];
let emailAddress = recipient["EMAIL_ADDRESS"];
......@@ -199,25 +200,36 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
let organisationId = recipient["ORGANISATION_ID"];
let email = mails[contactId];
let mailLogId = mailLogIds.get(contactId);
let recipientStatus = $KeywordRegistry.bulkMailRecipientStatus$sent();
let recipientStatus = $KeywordRegistry.bulkMailRecipientStatus$failed();
if (email !== undefined && emailAddress)
{
email.toRecipients = [emailAddress];
email.sender = emailSender;
email.subject = subjects[contactId];
try
{
email.toRecipients = [emailAddress];
email.sender = emailSender;
email.subject = subjects[contactId];
BulkMailUtils.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
isSuccess = email.send(sendUserTitle);
if (!isSuccess)
{
errorMessage = logging.toLogString(email.getMailError(), true);
var filterType = emailFilterProcessor.processError(errorMessage, contactId, emailAddress);
if (filterType == $KeywordRegistry.emailFilterType$bounceHard())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$hardBounce();
else if (filterType == $KeywordRegistry.emailFilterType$bounceSoft())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$softBounce();
BulkMailUtils.storeEmlFile(pBulkMailId, mailrunId, mailLogId,email.getEML());
isSuccess = email.send(sendUserTitle);
if (!isSuccess)
recipientStatus = bouncedStatus || $KeywordRegistry.bulkMailRecipientStatus$failed();
}
else
{
recipientStatus = $KeywordRegistry.bulkMailRecipientStatus$sent();
}
}
catch (ex)
{
var errorMessage = logging.toLogString(email.getMailError(), true);
var filterType = emailFilterProcessor.processError(errorMessage, contactId, emailAddress);
if (filterType == $KeywordRegistry.emailFilterType$bounceHard())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$hardBounce();
else if (filterType == $KeywordRegistry.emailFilterType$bounceSoft())
bouncedStatus = $KeywordRegistry.bulkMailRecipientStatus$softBounce();
recipientStatus = bouncedStatus || $KeywordRegistry.bulkMailRecipientStatus$failed();
errorMessage = logging.toLogString(ex, true);
}
}
......@@ -228,6 +240,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
"MAIL_LOGID": mailLogId,
"MAIL_RUN_ID": mailrunId,
"CONTACT_ID": contactId,
"ERRORMESSAGE": errorMessage,
"STATUS": recipientStatus,
"SENDER_EMAIL": emailSender,
"RECIPIENT_EMAIL": emailAddress,
......@@ -306,6 +319,7 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
{
let isSuccess = false;
let errorMessage = "";
let contactId = recipientData[i]["CONTACT_ID"];
let email = mails[contactId];
let currentMailLogId = mailLogIds.get(contactId);
......@@ -318,11 +332,19 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
{
if(testRecipientData[j][1])
{
email.toRecipients = [testRecipientData[j][1]];
let nextMailLogId = util.getNewUUID();
email.body = StringUtils.replaceAll(email.body,currentMailLogId,nextMailLogId);
currentMailLogId = nextMailLogId;
isSuccess = email.send(sendUserTitle);
try
{
email.toRecipients = [testRecipientData[j][1]];
email.body = StringUtils.replaceAll(email.body,currentMailLogId,nextMailLogId);
currentMailLogId = nextMailLogId;
this.storeEmlFile(pBulkMailId, mailrunId, nextMailLogId,email.getEML());
isSuccess = email.send(sendUserTitle);
}
catch(ex)
{
errorMessage = logging.toLogString(ex, true);
}
Array.prototype.push.call(isSuccess ? successIds : failedIds, recipientData[i]["BULKMAILRECIPIENTID"]);
......@@ -334,13 +356,13 @@ BulkMailUtils.sendBulkMail = function (pBulkMailId, pIsTestRun, pUser)
"MAIL_LOGID":nextMailLogId,
"MAIL_RUN_ID":mailrunId,
"CONTACT_ID":testRecipientData[j][0],
"ERRORMESSAGE": errorMessage || logging.toLogString(email.getMailError(), true) || "",
"STATUS":(isSuccess ?$KeywordRegistry.bulkMailRecipientStatus$sent(): $KeywordRegistry.bulkMailRecipientStatus$failed()),
"SENDER_EMAIL":emailSender,
"RECIPIENT_EMAIL":testRecipientData[j][1],
"MAILING_SUBJECT":email.subject,
"DATE_SEND":vars.get("$sys.date")
});
this.storeEmlFile(pBulkMailId, mailrunId, nextMailLogId,email.getEML());
});
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment