fix: exclude email from replyTo (#20953)

* fix: exclude email from replyTo

* update

* Update scheduleEmailReminders.ts
This commit is contained in:
Anik Dhabal Babu
2025-04-24 19:20:45 +00:00
committed by GitHub
parent 879ae597be
commit 2923684c7c
26 changed files with 116 additions and 79 deletions
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
@@ -14,7 +14,7 @@ export default class AttendeeAddGuestsEmail extends AttendeeScheduledEmail {
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.t("guests_added_event_type_subject", {
eventType: this.calEvent.type,
name: this.calEvent.team?.name || this.calEvent.organizer.name,
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import AttendeeScheduledEmail from "./attendee-scheduled-email";
@@ -8,7 +8,7 @@ export default class AttendeeAwaitingPaymentEmail extends AttendeeScheduledEmail
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.attendee.language.translate("complete_your_booking_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -15,7 +15,7 @@ export default class AttendeeCancelledEmail extends AttendeeScheduledEmail {
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.t("event_cancelled_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import AttendeeScheduledEmail from "./attendee-scheduled-email";
@@ -8,7 +8,7 @@ export default class AttendeeCancelledSeatEmail extends AttendeeScheduledEmail {
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.t("event_no_longer_attending_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,7 +1,7 @@
// TODO: We should find a way to keep App specific email templates within the App itself
import type { TFunction } from "i18next";
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
@@ -26,12 +26,10 @@ export default class AttendeeDailyVideoDownloadRecordingEmail extends BaseEmail
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.t("download_recording_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,6 +1,6 @@
import type { TFunction } from "i18next";
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
@@ -37,12 +37,10 @@ export default class AttendeeDailyVideoDownloadTranscriptEmail extends BaseEmail
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.t("download_transcript_email_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -9,7 +9,7 @@ export default class AttendeeDeclinedEmail extends AttendeeScheduledEmail {
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.t("event_declined_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
@@ -14,7 +14,7 @@ export default class AttendeeLocationChangeEmail extends AttendeeScheduledEmail
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.t("location_changed_event_type_subject", {
eventType: this.calEvent.type,
name: this.calEvent.team?.name || this.calEvent.organizer.name,
@@ -1,5 +1,5 @@
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -8,16 +8,13 @@ import AttendeeScheduledEmail from "./attendee-scheduled-email";
export default class AttendeeRequestEmail extends AttendeeScheduledEmail {
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
const toAddresses = this.calEvent.attendees.map((attendee) => attendee.email);
return {
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.calEvent.attendees[0].language.translate("booking_submitted_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -15,12 +15,10 @@ export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.attendee.language.translate("event_type_has_been_rescheduled_on_time_date", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -2,7 +2,7 @@ import type { TFunction } from "i18next";
import { default as cloneDeep } from "lodash/cloneDeep";
import { getRichDescription } from "@calcom/lib/CalEventParser";
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
@@ -40,12 +40,10 @@ export default class AttendeeScheduledEmail extends BaseEmail {
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.calEvent.title}`,
html: await this.getHtml(clonedCalEvent, this.attendee),
text: this.getTextBody(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -15,12 +15,10 @@ export default class AttendeeUpdatedEmail extends AttendeeScheduledEmail {
}),
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: [
...this.calEvent.attendees
.filter(({ email }) => email !== this.attendee.email)
.map(({ email }) => email),
getReplyToEmail(this.calEvent),
],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.filter(({ email }) => email !== this.attendee.email).map(({ email }) => email)
),
subject: `${this.attendee.language.translate("event_type_has_been_updated", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,4 @@
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import AttendeeScheduledEmail from "./attendee-scheduled-email";
@@ -9,7 +9,7 @@ export default class NoShowFeeChargedEmail extends AttendeeScheduledEmail {
return {
to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,
replyTo: getReplyToEmail(this.calEvent),
...getReplyToHeader(this.calEvent),
subject: `${this.attendee.language.translate("no_show_fee_charged_email_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,5 @@
import { APP_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
@@ -16,7 +17,10 @@ export default class OrganizerAddGuestsEmail extends OrganizerScheduledEmail {
}),
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("guests_added_event_type_subject", {
eventType: this.calEvent.type,
name: this.calEvent.attendees[0].name,
@@ -1,6 +1,7 @@
import type { TFunction } from "i18next";
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent } from "@calcom/types/Calendar";
@@ -23,7 +24,10 @@ export default class OrganizerDailyVideoDownloadRecordingEmail extends BaseEmail
return {
to: `${this.calEvent.organizer.email}>`,
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("download_recording_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,6 +1,7 @@
import type { TFunction } from "i18next";
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent } from "@calcom/types/Calendar";
@@ -35,7 +36,10 @@ export default class OrganizerDailyVideoDownloadTranscriptEmail extends BaseEmai
return {
to: `${this.calEvent.organizer.email}>`,
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("download_transcript_email_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,4 +1,5 @@
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import generateIcsFile, { GenerateIcsRole } from "../lib/generateIcsFile";
@@ -16,7 +17,10 @@ export default class OrganizerLocationChangeEmail extends OrganizerScheduledEmai
}),
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("location_changed_event_type_subject", {
eventType: this.calEvent.type,
name: this.calEvent.attendees[0].name,
@@ -1,5 +1,6 @@
import { checkIfUserHasFeatureController } from "@calcom/features/flags/operations/check-if-user-has-feature.controller";
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -21,7 +22,10 @@ export default class OrganizerRequestEmail extends OrganizerScheduledEmail {
return {
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("awaiting_approval")}: ${this.calEvent.title}`,
html: await this.getHtmlRequestEmail(template, this.calEvent, this.calEvent.organizer),
text: this.getTextBody("event_awaiting_approval"),
@@ -1,4 +1,5 @@
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { renderEmail } from "../";
import OrganizerRequestEmail from "./organizer-request-email";
@@ -10,7 +11,10 @@ export default class OrganizerRequestReminderEmail extends OrganizerRequestEmail
return {
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.t("event_awaiting_approval_subject", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -1,5 +1,5 @@
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToEmail } from "@calcom/lib/getReplyToEmail";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
@@ -9,7 +9,6 @@ import OrganizerScheduledEmail from "./organizer-scheduled-email";
export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
const toAddresses = [this.teamMember?.email || this.calEvent.organizer.email];
return {
icalEvent: generateIcsFile({
calEvent: this.calEvent,
@@ -18,7 +17,10 @@ export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
}),
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email), getReplyToEmail(this.calEvent)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.calEvent.organizer.language.translate("event_type_has_been_rescheduled_on_time_date", {
title: this.calEvent.title,
date: this.getFormattedDate(),
@@ -3,6 +3,7 @@ import { default as cloneDeep } from "lodash/cloneDeep";
import { getRichDescription } from "@calcom/lib/CalEventParser";
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
import { getReplyToHeader } from "@calcom/lib/getReplyToHeader";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
@@ -49,7 +50,10 @@ export default class OrganizerScheduledEmail extends BaseEmail {
}),
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","),
replyTo: [...this.calEvent.attendees.map(({ email }) => email)],
...getReplyToHeader(
this.calEvent,
this.calEvent.attendees.map(({ email }) => email)
),
subject: `${this.newSeat ? `${this.t("new_attendee")}: ` : ""}${this.calEvent.title}`,
html: await this.getHtml(
clonedCalEvent,
+2 -2
View File
@@ -14,7 +14,7 @@ export type WorkflowEmailData = {
to: string;
subject: string;
html: string;
replyTo: string;
replyTo?: string;
sender?: string | null;
attachments?: Attachment[];
};
@@ -31,7 +31,7 @@ export default class WorkflowEmail extends BaseEmail {
return {
to: this.mailData.to,
from: `${this.mailData.sender || SENDER_NAME} <${this.getMailerOptions().from}>`,
replyTo: this.mailData.replyTo,
...(this.mailData.replyTo && { replyTo: this.mailData.replyTo }),
subject: this.mailData.subject,
html: addHTMLStyles(this.mailData.html),
attachments: this.mailData.attachments,
@@ -332,10 +332,12 @@ export async function handler(req: NextRequest) {
html: emailContent.emailBody,
batchId: batchId,
sendAt: dayjs(reminder.scheduledDate).unix(),
replyTo:
reminder.booking?.eventType?.customReplyToEmail ??
reminder.booking?.userPrimaryEmail ??
reminder.booking.user?.email,
...(!reminder.booking?.eventType?.hideOrganizerEmail && {
replyTo:
reminder.booking?.eventType?.customReplyToEmail ??
reminder.booking?.userPrimaryEmail ??
reminder.booking.user?.email,
}),
attachments: reminder.workflowStep.includeCalendarEvent
? [
{
@@ -410,10 +412,12 @@ export async function handler(req: NextRequest) {
html: emailContent.emailBody,
batchId: batchId,
sendAt: dayjs(reminder.scheduledDate).unix(),
replyTo:
reminder.booking?.eventType?.customReplyToEmail ||
reminder.booking?.userPrimaryEmail ||
reminder.booking.user?.email,
...(!reminder.booking?.eventType?.hideOrganizerEmail && {
replyTo:
reminder.booking?.eventType?.customReplyToEmail ||
reminder.booking?.userPrimaryEmail ||
reminder.booking.user?.email,
}),
sender: reminder.workflowStep?.sender,
})
);
@@ -251,7 +251,7 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
return {
subject: emailContent.emailSubject,
html: emailContent.emailBody,
replyTo: evt?.eventType?.customReplyToEmail || evt.organizer.email,
...(!evt.hideOrganizerEmail && { replyTo: evt?.eventType?.customReplyToEmail || evt.organizer.email }),
attachments,
sender,
};
@@ -6,7 +6,7 @@ export const ZSendWorkflowEmailsSchema = z.object({
to: z.array(z.string()),
subject: z.string(),
html: z.string(),
replyTo: z.string(),
replyTo: z.string().optional(),
sender: z.string().nullable().optional(),
attachments: z
.array(
+16
View File
@@ -0,0 +1,16 @@
import type { CalendarEvent } from "@calcom/types/Calendar";
import { getReplyToEmail } from "./getReplyToEmail";
export function getReplyToHeader(calEvent: CalendarEvent, additionalEmails?: string | string[]) {
if (calEvent.hideOrganizerEmail) return {};
const replyToEmail = getReplyToEmail(calEvent);
const replyTo = additionalEmails
? Array.isArray(additionalEmails)
? [...additionalEmails, replyToEmail]
: [additionalEmails, replyToEmail]
: replyToEmail;
return { replyTo };
}