fix resend send error

This commit is contained in:
oiov
2025-07-28 11:03:15 +08:00
parent 17df046ca1
commit 2d2a30cd8b
2 changed files with 21 additions and 1 deletions
+7 -1
View File
@@ -1,3 +1,4 @@
import { getConfiguredResendDomains } from "@/lib/dto/domains";
import { OriginalEmail, saveForwardEmail } from "@/lib/dto/email";
import { getMultipleConfigs } from "@/lib/dto/system-config";
import { resend } from "@/lib/email";
@@ -116,8 +117,13 @@ async function handleExternalForward(data: OriginalEmail, configs: any) {
throw new Error("No valid forward emails configured");
}
const sender = await getConfiguredResendDomains();
if (sender.length === 0) {
throw new Error("No configured resend domains");
}
const { error } = await resend.emails.send({
from: data.from,
from: `forward@${sender[0].domain_name}`,
to: validEmails,
subject: data.subject ?? "No subject",
html: data.html ?? data.text ?? "-",
+14
View File
@@ -132,6 +132,20 @@ export async function checkDomainIsConfiguratedResend(domain_name: string) {
}
}
export async function getConfiguredResendDomains() {
try {
const domains = await prisma.domain.findMany({
where: { resend_api_key: { not: null } },
select: {
domain_name: true,
},
});
return domains;
} catch (error) {
return [];
}
}
export async function createDomain(data: DomainConfig) {
try {
const createdDomain = await prisma.domain.create({ data });