* Init Maizzle * Initial template JSX conversion and testing * WIP * WIP * WIP * WIP * WIP * Migrated AttendeeRescheduledEmail * WIP * WIP * DRY * Cleanup * Cleanup * Cleanup * Migrate feedback email * Migrates ForgotPasswordEmail * Migrates OrganizerCancelledEmail * Migrated OrganizerLocationChangeEmail * Formatting * Migrated AttendeeRequestRescheduledEmail * Migrates OrganizerPaymentRefundFailedEmail * Migrates OrganizerRequestEmail * Migrates OrganizerRequestReminderEmail * Fixes type-check * Moved email-manager to package * Import fixes * Removed duplicate email code from vital app * Removed duplicate email code from wipemycal * Build/type fixes * Fixes web email imports * Fixes build * Embed build fixes * Update AttendeeAwaitingPaymentEmail.tsx * Update default-cookies.ts * Revert "Embed build fixes" This reverts commit 8d693e99aca6dfe92d5cbb27ffa962545c3e9389. * Embed build fixes # Conflicts: # packages/embeds/embed-core/package.json * dep and email date fixes * Update attendee-scheduled-email.ts * Update package.json * Update [...nextauth].tsx * Update email.ts * Prevents /api/email on production builds Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import dayjs, { Dayjs } from "dayjs";
|
|
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
import timezone from "dayjs/plugin/timezone";
|
|
import toArray from "dayjs/plugin/toArray";
|
|
import utc from "dayjs/plugin/utc";
|
|
import nodemailer from "nodemailer";
|
|
|
|
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
|
import { serverConfig } from "@calcom/lib/serverConfig";
|
|
|
|
dayjs.extend(utc);
|
|
dayjs.extend(timezone);
|
|
dayjs.extend(localizedFormat);
|
|
dayjs.extend(toArray);
|
|
|
|
export default class BaseEmail {
|
|
name = "";
|
|
|
|
protected getTimezone() {
|
|
return "";
|
|
}
|
|
|
|
protected getRecipientTime(time: string): Dayjs;
|
|
protected getRecipientTime(time: string, format: string): string;
|
|
protected getRecipientTime(time: string, format?: string) {
|
|
const date = dayjs(time).tz(this.getTimezone());
|
|
if (typeof format === "string") return date.format(format);
|
|
return date;
|
|
}
|
|
|
|
protected getNodeMailerPayload(): Record<string, unknown> {
|
|
return {};
|
|
}
|
|
public sendEmail() {
|
|
if (process.env.NEXT_PUBLIC_IS_E2E) return new Promise((r) => r("Skipped sendEmail for E2E"));
|
|
new Promise((resolve, reject) =>
|
|
nodemailer
|
|
.createTransport(this.getMailerOptions().transport)
|
|
.sendMail(this.getNodeMailerPayload(), (_err, info) => {
|
|
if (_err) {
|
|
const err = getErrorFromUnknown(_err);
|
|
this.printNodeMailerError(err);
|
|
reject(err);
|
|
} else {
|
|
resolve(info);
|
|
}
|
|
})
|
|
).catch((e) => console.error("sendEmail", e));
|
|
return new Promise((resolve) => resolve("send mail async"));
|
|
}
|
|
|
|
protected getMailerOptions() {
|
|
return {
|
|
transport: serverConfig.transport,
|
|
from: serverConfig.from,
|
|
};
|
|
}
|
|
|
|
protected printNodeMailerError(error: Error): void {
|
|
/** Don't clog the logs with unsent emails in E2E */
|
|
if (process.env.NEXT_PUBLIC_IS_E2E) return;
|
|
console.error(`${this.name}_ERROR`, error);
|
|
}
|
|
}
|