Files
sign/packages/lib/mail/sendMail.ts

24 lines
582 B
TypeScript
Raw Normal View History

2023-01-26 16:20:48 +01:00
import nodemailer from "nodemailer";
import nodemailerSendgrid from "nodemailer-sendgrid";
export const sendMail = async (to: string, subject: string, body: string) => {
2023-01-26 16:20:48 +01:00
if (!process.env.SENDGRID_API_KEY)
throw new Error("Sendgrid API Key not set.");
const transport = await nodemailer.createTransport(
2023-01-26 16:20:48 +01:00
nodemailerSendgrid({
apiKey: process.env.SENDGRID_API_KEY || "",
})
);
await transport
.sendMail({
from: process.env.MAIL_FROM,
to: to,
subject: subject,
html: body,
})
.catch((err) => {
throw err;
});
2023-01-26 16:20:48 +01:00
};