Resolve bounced email tracking.
This commit is contained in:
@@ -148,7 +148,7 @@ exports.sendEmail = async (req, res) => {
|
||||
to: req.body.to,
|
||||
cc: req.body.cc,
|
||||
subject: req.body.subject,
|
||||
messageId: info.messageId,
|
||||
messageId: info.response,
|
||||
});
|
||||
res.json({
|
||||
success: true, //response: info
|
||||
@@ -182,7 +182,7 @@ async function getImage(imageUrl) {
|
||||
|
||||
async function logEmail(req, email) {
|
||||
try {
|
||||
await client.request(queries.INSERT_EMAIL_AUDIT, {
|
||||
const insertresult = await client.request(queries.INSERT_EMAIL_AUDIT, {
|
||||
email: {
|
||||
to: email.to,
|
||||
cc: email.cc,
|
||||
@@ -195,6 +195,7 @@ async function logEmail(req, email) {
|
||||
status: "Sent",
|
||||
},
|
||||
});
|
||||
console.log(insertresult);
|
||||
} catch (error) {
|
||||
logger.log("email-log-error", "error", req.user.email, null, {
|
||||
from: `${req.body.from.name} <${req.body.from.address}>`,
|
||||
@@ -214,19 +215,17 @@ exports.emailBounce = async function (req, res, next) {
|
||||
body: req.body,
|
||||
});
|
||||
}
|
||||
if (body.notificationType === "Bounce") {
|
||||
// const message = JSON.parse(body.Message);
|
||||
const message = JSON.parse(body.Message);
|
||||
if (message.notificationType === "Bounce") {
|
||||
let replyTo, subject, messageId;
|
||||
body.mail.headers.forEach((header) => {
|
||||
message.mail.headers.forEach((header) => {
|
||||
if (header.name === "Reply-To") {
|
||||
replyTo = header.value;
|
||||
} else if (header.name === "Subject") {
|
||||
subject = header.value;
|
||||
} else if (header.name === "Message-ID") {
|
||||
messageId = header.value;
|
||||
}
|
||||
});
|
||||
|
||||
messageId = message.mail.messageId;
|
||||
if (replyTo === "noreply@imex.online") {
|
||||
res.sendStatus(200);
|
||||
return;
|
||||
@@ -235,13 +234,13 @@ exports.emailBounce = async function (req, res, next) {
|
||||
const result = await client.request(queries.UPDATE_EMAIL_AUDIT, {
|
||||
sesid: messageId,
|
||||
status: "Bounced",
|
||||
context: body.bounce?.bouncedRecipients,
|
||||
context: message.bounce?.bouncedRecipients,
|
||||
});
|
||||
transporter.sendMail(
|
||||
{
|
||||
from: `ImEX Online <noreply@imex.online>`,
|
||||
to: replyTo,
|
||||
bcc: "patrick@snapt.ca",
|
||||
//bcc: "patrick@snapt.ca",
|
||||
subject: `ImEX Online Bounced Email - RE: ${subject}`,
|
||||
text: `ImEX Online has tried to deliver an email with the subject: ${subject} to the intended recipients but encountered an error.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user