feat:add email send functionality
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
|
||||
export const getEmailsByType = async (type) => {
|
||||
try {
|
||||
const emails = await prisma.emailConfig.findMany({
|
||||
where: {
|
||||
type,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
return emails.map((e) => e.email).join(",");
|
||||
} catch (error) {
|
||||
console.error("Fetch email config error:", error);
|
||||
return "";
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import postmark from "postmark";
|
||||
|
||||
const client = new postmark.ServerClient(process.env.POSTMARK_API_KEY);
|
||||
|
||||
export const sendEmail = async ({to, subject, html, text}) => {
|
||||
try {
|
||||
await client.sendEmail({
|
||||
From: process.env.EMAIL_FROM,
|
||||
To: to,
|
||||
Subject: subject,
|
||||
HtmlBody: html,
|
||||
TextBody: text || "",
|
||||
MessageStream: "outbound",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Email send error:", error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user