Add replyto option

This commit is contained in:
KMKoushik
2024-05-16 07:18:44 +10:00
parent 2b77ef3413
commit 3df022f6b2
8 changed files with 16 additions and 3 deletions

View File

@@ -108,6 +108,7 @@ export async function sendEmailThroughSes({
subject,
text,
html,
replyTo,
region = "us-east-1",
configurationSetName,
}: EmailContent & {
@@ -117,6 +118,7 @@ export async function sendEmailThroughSes({
const sesClient = getSesClient(region);
const command = new SendEmailCommand({
FromEmailAddress: from,
ReplyToAddresses: replyTo ? [replyTo] : undefined,
Destination: {
ToAddresses: [to],
},
@@ -155,10 +157,12 @@ export async function sendEmailThroughSes({
}
}
// Need to improve this. Use some kinda library to do this
export async function sendEmailWithAttachments({
to,
from,
subject,
replyTo,
// eslint-disable-next-line no-unused-vars
text,
html,
@@ -174,13 +178,13 @@ export async function sendEmailWithAttachments({
const boundary = "NextPart";
let rawEmail = `From: ${from}\n`;
rawEmail += `To: ${to}\n`;
rawEmail += `Reply-To: ${replyTo}\n`;
rawEmail += `Subject: ${subject}\n`;
rawEmail += `MIME-Version: 1.0\n`;
rawEmail += `Content-Type: multipart/mixed; boundary="${boundary}"\n\n`;
rawEmail += `--${boundary}\n`;
rawEmail += `Content-Type: text/html; charset="UTF-8"\n\n`;
rawEmail += `${html}\n\n`;
for (const attachment of attachments) {
const content = attachment.content; // Convert buffer to base64
const mimeType =

View File

@@ -15,6 +15,7 @@ const route = createRoute({
to: z.string().email(),
from: z.string().email(),
subject: z.string(),
replyTo: z.string().optional(),
text: z.string().optional(),
html: z.string().optional(),
attachments: z

View File

@@ -1,6 +1,7 @@
import { OpenAPIHono } from "@hono/zod-openapi";
import { swaggerUI } from "@hono/swagger-ui";
import { handleError } from "./api-error";
import { env } from "~/env";
export function getApp() {
const app = new OpenAPIHono().basePath("/api");
@@ -14,7 +15,7 @@ export function getApp() {
version: "1.0.0",
title: "Unsend API",
},
servers: [{ url: `${new URL(c.req.url).origin}/api` }],
servers: [{ url: `${env.APP_URL}/api` }],
}));
app.openAPIRegistry.registerComponent("securitySchemes", "Bearer", {

View File

@@ -6,7 +6,8 @@ import { queueEmail } from "./job-service";
export async function sendEmail(
emailContent: EmailContent & { teamId: number }
) {
const { to, from, subject, text, html, teamId, attachments } = emailContent;
const { to, from, subject, text, html, teamId, attachments, replyTo } =
emailContent;
const fromDomain = from.split("@")[1];
@@ -34,6 +35,7 @@ export async function sendEmail(
to,
from,
subject,
replyTo,
text,
html,
teamId,

View File

@@ -81,6 +81,7 @@ async function executeEmail(
to: email.to,
from: email.from,
subject: email.subject,
replyTo: email.replyTo ?? undefined,
text: email.text ?? undefined,
html: email.html ?? undefined,
region: domain?.region ?? env.AWS_DEFAULT_REGION,

View File

@@ -4,6 +4,7 @@ export type EmailContent = {
subject: string;
text?: string;
html?: string;
replyTo?: string;
attachments?: Array<EmailAttachment>;
};