Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

revert send email changes

Gaurav Bhatt13e69a18bc08
diff --git a/packages/jobs/src/inngest/functions/notifications/send-email.ts b/packages/jobs/src/inngest/functions/notifications/send-email.ts
index e507602257..9887d2efea 100644
--- a/packages/jobs/src/inngest/functions/notifications/send-email.ts
+++ b/packages/jobs/src/inngest/functions/notifications/send-email.ts
@@ -1,5 +1,4 @@
-import { getCarbonServiceRole } from "@carbon/auth/client.server";
-import { Email as EmailConfig } from "@carbon/ee";
+import { RESEND_DOMAIN } from "@carbon/env";
import { NonRetriableError, serializeError } from "inngest";
import { Resend } from "resend";
import { inngest } from "../../client";
@@ -12,7 +11,6 @@ export const sendEmailFunction = inngest.createFunction(
{ event: "carbon/send-email" },
async ({ event, step }) => {
const payload = event.data;
- const serviceRole = getCarbonServiceRole();
// Resend rejects the request if `to` or `cc` contain null/undefined
// entries, so strip falsy values regardless of what callers pass.
@@ -38,110 +36,29 @@ export const sendEmailFunction = inngest.createFunction(
);
}
- const { companyName, integrationMetadata, integrationActive } =
- await step.run("fetch-company-integration", async () => {
- const [companyResult, integrationResult] = await Promise.all([
- serviceRole
- .from("company")
- .select("name")
- .eq("id", payload.companyId)
- .single(),
- serviceRole
- .from("companyIntegration")
- .select("active, metadata")
- .eq("companyId", payload.companyId)
- .eq("id", "email")
- .maybeSingle()
- ]);
-
- return {
- companyName: companyResult.data?.name ?? null,
- integrationActive: integrationResult.data?.active ?? false,
- integrationMetadata: integrationResult.data?.metadata ?? null
- };
- });
-
- // Legacy installs predate the provider field — default them to Resend so
- // existing configs keep working without any migration step on the caller.
- const metadataWithProvider =
- integrationMetadata && typeof integrationMetadata === "object"
- ? {
- provider: "resend",
- ...(integrationMetadata as Record<string, unknown>)
- }
- : integrationMetadata;
-
- const parsedMetadata = EmailConfig.schema.safeParse(metadataWithProvider);
-
- if (!parsedMetadata.success || !integrationActive) {
- return { success: false, message: "Invalid or inactive integration" };
- }
-
- const data = parsedMetadata.data as {
- provider: "resend" | "smtp";
- fromEmail: string;
- apiKey?: string;
- host?: string;
- port?: number;
- username?: string;
- password?: string;
- secure?: boolean;
- };
-
- const fromAddress = `${companyName} <${data.fromEmail}>`;
-
- if (data.provider === "smtp") {
- const result = await step.run("send-email", async () => {
- const nodemailer = await import("nodemailer");
- const transporter = nodemailer.createTransport({
- host: data.host!,
- port: data.port!,
- secure: data.secure === true,
- auth: {
- user: data.username!,
- pass: data.password!
- }
- });
-
- console.info(`SMTP Email Job`);
- return transporter.sendMail({
- from: fromAddress,
- to: toRecipients,
- cc: ccRecipients,
- replyTo: payload.from,
- subject: payload.subject,
- html: payload.html,
- text: payload.text,
- attachments: payload.attachments?.map(
- (a: { filename: string; content: string }) => ({
- filename: a.filename,
- content: a.content,
- encoding: "base64" as const
- })
- )
- });
- });
-
- return { success: true, result };
- }
+ const fromAddress = `Carbon <no-reply@${RESEND_DOMAIN}>`;
const result = await step.run("send-email", async () => {
- const resend = new Resend(data.apiKey!);
+ if (process.env.DISABLE_RESEND) {
+ console.info(`Resend disabled — skipping send to`, toRecipients);
+ return null;
+ }
+
+ const resend = new Resend(process.env.RESEND_API_KEY!);
const email = {
- from: fromAddress,
- to: toRecipients,
+ attachments: payload.attachments,
cc: ccRecipients,
+ from: fromAddress,
+ html: payload.html,
reply_to: payload.from,
subject: payload.subject,
- html: payload.html,
text: payload.text,
- attachments: payload.attachments
+ to: toRecipients
};
console.info(`Resend Email Job`);
const response = await resend.emails.send(email);
-
if (response.error) {
if (response.error.name === "validation_error") {
throw new NonRetriableError(
@@ -150,10 +67,9 @@ export const sendEmailFunction = inngest.createFunction(
}
throw new Error(`Resend error: ${serializeError(response.error)}`);
}
-
return response.data;
});
- return { success: true, result };
+ return { result, success: true };
}
);