convert text to html for marketing emails (#55)
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
"bullmq": "^5.8.2",
|
||||
"date-fns": "^3.6.0",
|
||||
"hono": "^4.2.2",
|
||||
"html-to-text": "^9.0.5",
|
||||
"install": "^0.13.0",
|
||||
"ioredis": "^5.4.1",
|
||||
"lucide-react": "^0.359.0",
|
||||
@@ -63,6 +64,7 @@
|
||||
"@next/eslint-plugin-next": "^14.2.2",
|
||||
"@prisma/extension-optimize": "^0.10.0",
|
||||
"@types/eslint": "^8.56.2",
|
||||
"@types/html-to-text": "^9.0.4",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^20.11.20",
|
||||
"@types/react": "^18.2.57",
|
||||
|
@@ -141,14 +141,18 @@ export async function sendEmailThroughSes({
|
||||
},
|
||||
Body: {
|
||||
// Body
|
||||
Text: {
|
||||
Data: text, // required
|
||||
Charset: "UTF-8",
|
||||
},
|
||||
Html: {
|
||||
Data: html, // required
|
||||
Charset: "UTF-8",
|
||||
},
|
||||
Text: text
|
||||
? {
|
||||
Data: text, // required
|
||||
Charset: "UTF-8",
|
||||
}
|
||||
: undefined,
|
||||
Html: html
|
||||
? {
|
||||
Data: html, // required
|
||||
Charset: "UTF-8",
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
...(unsubUrl
|
||||
? {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Job, Queue, Worker } from "bullmq";
|
||||
import { env } from "~/env";
|
||||
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";
|
||||
@@ -164,13 +165,19 @@ async function executeEmail(
|
||||
console.log(`[EmailQueueService]: Sending email ${email.id}`);
|
||||
const unsubUrl = job.data.unsubUrl;
|
||||
|
||||
const text = email.text
|
||||
? email.text
|
||||
: email.campaignId && email.html
|
||||
? htmlToText(email.html)
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
const messageId = attachments.length
|
||||
? await sendEmailWithAttachments({
|
||||
to: email.to,
|
||||
from: email.from,
|
||||
subject: email.subject,
|
||||
text: email.text ?? "",
|
||||
text,
|
||||
html: email.html ?? undefined,
|
||||
region: domain?.region ?? env.AWS_DEFAULT_REGION,
|
||||
configurationSetName,
|
||||
@@ -181,7 +188,7 @@ async function executeEmail(
|
||||
from: email.from,
|
||||
subject: email.subject,
|
||||
replyTo: email.replyTo ?? undefined,
|
||||
text: email.text ?? "",
|
||||
text,
|
||||
html: email.html ?? undefined,
|
||||
region: domain?.region ?? env.AWS_DEFAULT_REGION,
|
||||
configurationSetName,
|
||||
@@ -192,7 +199,7 @@ async function executeEmail(
|
||||
// Delete attachments after sending the email
|
||||
await db.email.update({
|
||||
where: { id: email.id },
|
||||
data: { sesEmailId: messageId, attachments: undefined },
|
||||
data: { sesEmailId: messageId, text, attachments: undefined },
|
||||
});
|
||||
} catch (error: any) {
|
||||
await db.emailEvent.create({
|
||||
|
Reference in New Issue
Block a user