feat: add In-Reply-To option (#165)

This commit is contained in:
KM Koushik
2025-05-25 20:44:13 +10:00
committed by GitHub
parent ff32ff9302
commit 15e5327024
14 changed files with 754 additions and 592 deletions

View File

@@ -4,7 +4,7 @@ import { EmailAttachment } from "~/types";
import { convert as htmlToText } from "html-to-text";
import { getConfigurationSetName } from "~/utils/ses-utils";
import { db } from "../db";
import { sendEmailThroughSes, sendEmailWithAttachments } from "../aws/ses";
import { sendRawEmail } from "../aws/ses";
import { getRedis } from "../redis";
import { DEFAULT_QUEUE_OPTIONS } from "../queue/queue-constants";
import { Prisma } from "@prisma/client";
@@ -331,34 +331,37 @@ async function executeEmail(
? htmlToText(email.html)
: undefined;
let inReplyToMessageId: string | undefined = undefined;
if (email.inReplyToId) {
const replyEmail = await db.email.findUnique({
where: {
id: email.inReplyToId,
},
});
if (replyEmail && replyEmail.sesEmailId) {
inReplyToMessageId = replyEmail.sesEmailId;
}
}
try {
const messageId = attachments.length
? await sendEmailWithAttachments({
to: email.to,
from: email.from,
subject: email.subject,
replyTo: email.replyTo ?? undefined,
bcc: email.bcc,
cc: email.cc,
text,
html: email.html ?? undefined,
region: domain?.region ?? env.AWS_DEFAULT_REGION,
configurationSetName,
attachments,
})
: await sendEmailThroughSes({
to: email.to,
from: email.from,
subject: email.subject,
replyTo: email.replyTo ?? undefined,
text,
html: email.html ?? undefined,
region: domain?.region ?? env.AWS_DEFAULT_REGION,
configurationSetName,
attachments,
unsubUrl,
isBulk,
});
const messageId = await sendRawEmail({
to: email.to,
from: email.from,
subject: email.subject,
replyTo: email.replyTo ?? undefined,
bcc: email.bcc,
cc: email.cc,
text,
html: email.html ?? undefined,
region: domain?.region ?? env.AWS_DEFAULT_REGION,
configurationSetName,
attachments: attachments.length > 0 ? attachments : undefined,
unsubUrl,
isBulk,
inReplyToMessageId,
});
// Delete attachments after sending the email
await db.email.update({