Add replyto option
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Email" ADD COLUMN "replyTo" TEXT;
|
@@ -157,6 +157,7 @@ model Email {
|
||||
to String
|
||||
from String
|
||||
subject String
|
||||
replyTo String?
|
||||
text String?
|
||||
html String?
|
||||
latestStatus EmailStatus @default(QUEUED)
|
||||
|
@@ -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 =
|
||||
|
@@ -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
|
||||
|
@@ -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", {
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -4,6 +4,7 @@ export type EmailContent = {
|
||||
subject: string;
|
||||
text?: string;
|
||||
html?: string;
|
||||
replyTo?: string;
|
||||
attachments?: Array<EmailAttachment>;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user