cairo/lib/util/mailing.ts

17 lines
726 B
TypeScript
Raw Normal View History

2024-08-24 12:41:04 -06:00
import sgMail from "@sendgrid/mail";
const { CAIRO_BOT_EMAIL: botEmail, CAIRO_SENDGRID_KEY: sendgridApiKey } = process.env;
// Configure API Key
sgMail.setApiKey(sendgridApiKey ?? "");
if (!botEmail && !!sendgridApiKey) throw Error("Bot Email wasn't defined but API key was!");
const from = botEmail ?? "donotreply@dunemask.dev";
const ignoreMessage = `If you did not sign up for a cairo account, please ignore this email!`;
export const sendMessage = (to: string, subject: string, text: string) =>
sgMail.send({ from, to, subject, text: text + `\n${ignoreMessage}` });
export const sendHtml = (to: string, subject: string, html: string) =>
sgMail.send({ from, to, subject, html: html + `<p>${ignoreMessage}</p>` });