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

34 lines
736 B
TypeScript
Raw Normal View History

2023-02-21 17:42:30 +01:00
import { ReadStream } from "fs";
2023-01-26 16:20:48 +01:00
import nodemailer from "nodemailer";
import nodemailerSendgrid from "nodemailer-sendgrid";
2023-02-21 17:42:30 +01:00
export const sendMail = async (
to: string,
subject: string,
body: string,
attachments: {
filename: string;
content: string | Buffer;
}[] = []
) => {
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,
2023-02-21 17:42:30 +01:00
attachments: attachments,
})
.catch((err) => {
throw err;
});
2023-01-26 16:20:48 +01:00
};