nodemailer and sendgrid integration
This commit is contained in:
24
packages/lib/mail/sendMail.ts
Normal file
24
packages/lib/mail/sendMail.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import nodemailer from "nodemailer";
|
||||
import nodemailerSendgrid from "nodemailer-sendgrid";
|
||||
|
||||
export const sendMail = async (
|
||||
to: string,
|
||||
subject: string,
|
||||
htmlFormattedMessage: string
|
||||
) => {
|
||||
if (!process.env.SENDGRID_API_KEY)
|
||||
throw new Error("Sendgrid API Key not set.");
|
||||
|
||||
const transport = nodemailer.createTransport(
|
||||
nodemailerSendgrid({
|
||||
apiKey: process.env.SENDGRID_API_KEY || "",
|
||||
})
|
||||
);
|
||||
|
||||
await transport.sendMail({
|
||||
from: process.env.SENDGRID_API_KEY,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: htmlFormattedMessage,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user