Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/email-wizard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function EmailWizardContent({
subject: formData.subject,
content: formData.content,
previewText: formData.previewText,
replyTo: formData.replyTo,
segmentId: formData.selectedSegment || undefined,
scheduledTime,
organizationId,
Expand Down
1 change: 1 addition & 0 deletions components/email-wizard/step-4-schedule-send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function Step4ScheduleSend({
subject: formData.subject,
content: formData.content,
previewText: formData.previewText,
replyTo: formData.replyTo,
organizationId,
audienceListId: formData.audienceListId || undefined,
});
Expand Down
4 changes: 4 additions & 0 deletions components/modal/send-email-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface SendEmailModalProps {
subject: string;
previewText: string;
from: string;
replyTo?: string | null;
content: string;
emailId: string;
audienceListId?: string | null;
Expand All @@ -48,6 +49,7 @@ export function SendEmailModal({
subject,
previewText,
from,
replyTo,
content,
emailId,
audienceListId: audienceListIdProp,
Expand Down Expand Up @@ -89,6 +91,7 @@ export function SendEmailModal({
subject,
content,
previewText,
replyTo,
organizationId,
audienceListId: audienceListIdProp || selectedAudienceList || undefined,
});
Expand Down Expand Up @@ -135,6 +138,7 @@ export function SendEmailModal({
subject,
content,
previewText,
replyTo,
scheduledTime: mode === "now" ? "" : when,
id: emailId,
organizationId,
Expand Down
3 changes: 3 additions & 0 deletions components/send-email-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface SendEmailButtonProps {
subject: string;
previewText: string;
from: string;
replyTo?: string | null;
content: string;
emailId: string;
onSent?: () => void;
Expand All @@ -40,6 +41,7 @@ export default function SendEmailButton({
subject,
previewText,
from,
replyTo,
content,
emailId,
onConfirm,
Expand All @@ -60,6 +62,7 @@ export default function SendEmailButton({
subject={subject}
previewText={previewText}
from={from}
replyTo={replyTo}
content={content}
emailId={emailId}
onConfirm={(scheduledTime) => {
Expand Down
38 changes: 38 additions & 0 deletions lib/actions/send-email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,44 @@ describe("sendBulkEmail SES scheduling", () => {
expect(delayMs).toBeLessThanOrEqual(24 * 60 * 60 * 1000 + 5000);
});

test("passes replyTo into queued job data", async () => {
const { sendBulkEmail } = await import("@/lib/actions/send-email");
const scheduledTime = new Date(Date.now() + 60 * 60 * 1000).toISOString();

await sendBulkEmail({
id: "email-1",
organizationId: "org-1",
from: "Sender",
subject: "Subject",
content: null,
previewText: null,
replyTo: " replies@example.com ",
scheduledTime,
});

const [jobs] = mockQueueBulkEmails.mock.calls[0];
expect(jobs[0].replyTo).toBe("replies@example.com");
});

test("omits replyTo from queued job data when it is whitespace only", async () => {
const { sendBulkEmail } = await import("@/lib/actions/send-email");
const scheduledTime = new Date(Date.now() + 60 * 60 * 1000).toISOString();

await sendBulkEmail({
id: "email-1",
organizationId: "org-1",
from: "Sender",
subject: "Subject",
content: null,
previewText: null,
replyTo: " ",
scheduledTime,
});

const [jobs] = mockQueueBulkEmails.mock.calls[0];
expect(jobs[0].replyTo).toBeUndefined();
});

test("saves scheduledJobIds to database when all jobs queued", async () => {
const { default: prisma } = await import("@/lib/prisma");
const { sendBulkEmail } = await import("@/lib/actions/send-email");
Expand Down
7 changes: 7 additions & 0 deletions lib/actions/send-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export type SendEmailOpts = {
react?: React.ReactElement;
organizationId?: string;
audienceListId?: string | null;
replyTo?: string | null;
};

export const sendEmail = async ({
Expand All @@ -177,6 +178,7 @@ export const sendEmail = async ({
react,
organizationId,
audienceListId,
replyTo,
}: SendEmailOpts) => {
const {
client,
Expand Down Expand Up @@ -268,6 +270,7 @@ export const sendEmail = async ({
subject: subject || "No Subject",
html: htmlContent,
text: previewText ?? "",
replyTo: replyTo?.trim() || undefined,
});

if (result.error) {
Expand Down Expand Up @@ -296,6 +299,7 @@ export const sendBulkEmail = async ({
id,
organizationId,
segmentId,
replyTo,
}: {
audienceListId?: string | null;
from: string;
Expand All @@ -306,6 +310,7 @@ export const sendBulkEmail = async ({
id: string;
organizationId: string;
segmentId?: string | null;
replyTo?: string | null;
}) => {
const session = await getSession();
if (!session?.user.id) return { error: "Not authenticated" };
Expand Down Expand Up @@ -465,6 +470,7 @@ export const sendBulkEmail = async ({
subject: subject || "No Subject",
html: htmlContent || "",
text: previewText ?? "",
replyTo: replyTo?.trim() || undefined,
organizationId,
provider,
awsRegion,
Expand Down Expand Up @@ -536,6 +542,7 @@ export const sendBulkEmail = async ({
subject: subject || "No Subject",
html: htmlContent || "",
text: previewText ?? "",
replyTo: replyTo?.trim() || undefined,
tags: [
{ name: "intrepidId", value: id },
{ name: "userId", value: session.user.id },
Expand Down
Loading