cairo/lib/util/mailing.ts
Dunemask 0fc5f05b6a
Some checks failed
Deploy Edge / deploy-edge (push) Failing after 2s
S3 Repo Backup / s3-repo-backup (push) Failing after 2s
[INIT] Initial Project Structure
2024-08-24 12:41:04 -06:00

16 lines
726 B
TypeScript

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>` });