shellphone.app/mailers/subscribe-notification-mailer.ts

36 lines
850 B
TypeScript
Raw Normal View History

2021-11-01 23:13:30 +00:00
import previewEmail from "preview-email";
import { sendEmail } from "integrations/aws-ses";
import { render } from "./renderer";
type ResetPasswordMailer = {
to: string;
userName: string;
};
export async function subscribeNotificationMailer({ to, userName }: ResetPasswordMailer) {
const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN;
const phoneSettingsUrl = `${origin}/settings/phone`;
const html = await render("subscribe-notification", { name: userName, phoneSettingsUrl });
const msg = {
from: "mokhtar@shellphone.app",
to,
subject: "Your Shellphone subscription",
html,
};
return {
async send() {
if (process.env.NODE_ENV === "production") {
return sendEmail({
recipients: [msg.to],
subject: msg.subject,
html: msg.html,
});
}
return previewEmail(msg);
},
};
}