mailing template and send sign request error handling
This commit is contained in:
@@ -1,24 +1,23 @@
|
||||
import nodemailer from "nodemailer";
|
||||
import nodemailerSendgrid from "nodemailer-sendgrid";
|
||||
|
||||
export const sendMail = async (
|
||||
to: string,
|
||||
subject: string,
|
||||
htmlFormattedMessage: string
|
||||
) => {
|
||||
export const sendMail = async (to: string, subject: string, body: string) => {
|
||||
if (!process.env.SENDGRID_API_KEY)
|
||||
throw new Error("Sendgrid API Key not set.");
|
||||
|
||||
const transport = nodemailer.createTransport(
|
||||
const transport = await nodemailer.createTransport(
|
||||
nodemailerSendgrid({
|
||||
apiKey: process.env.SENDGRID_API_KEY || "",
|
||||
})
|
||||
);
|
||||
|
||||
await transport.sendMail({
|
||||
from: process.env.MAIL_FROM,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: htmlFormattedMessage,
|
||||
});
|
||||
await transport
|
||||
.sendMail({
|
||||
from: process.env.MAIL_FROM,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: body,
|
||||
})
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user