Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langfuse Langfuse SendBatchExportSuccessEmail

From Leeroopedia
Revision as of 13:14, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Langfuse_Langfuse_SendBatchExportSuccessEmail.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Batch Export, Email Notification, SMTP
Last Updated 2026-02-14 00:00 GMT

Overview

Concrete tool for sending email notifications with download links when batch exports complete, provided by Langfuse.

Description

sendBatchExportSuccessEmail is an asynchronous function that sends a transactional email to the user who initiated a batch export. It uses the following technology stack:

  • nodemailer: The standard Node.js email sending library. A transport is created from the SMTP_CONNECTION_URL environment variable, which is parsed via parseConnectionUrl to extract SMTP host, port, authentication, and TLS settings.
  • @react-email/render: Converts the BatchExportSuccessEmailTemplate React component into static HTML at runtime. This allows the email template to be written as a React component using @react-email/components (Body, Button, Container, Heading, Text, etc.) and styled with Tailwind CSS.
  • BatchExportSuccessEmailTemplate: The React component that defines the email layout. It includes the Langfuse logo, a heading ("Your data export is ready"), a personalized greeting, the export name in monospace font, a prominent "Download Export" button linking to the signed URL, a note about column ordering, and a footer with the recipient's email address.

The function implements graceful degradation:

  • If EMAIL_FROM_ADDRESS or SMTP_CONNECTION_URL is not set, it logs an error and returns without throwing.
  • If the email sending fails (SMTP error, network issue), the error is logged but not re-thrown, ensuring the calling code (handleBatchExportJob) is not affected.

The email subject line is always "Your data export is ready", and the sender is identified as "Langfuse" with the configured from address.

Usage

Called at the end of handleBatchExportJob after the export file has been uploaded to blob storage and the database record has been updated to COMPLETED. Only called if the requesting user has an email address on their user record.

Code Reference

Source Location

  • Repository: langfuse
  • Files:
    • packages/shared/src/server/services/email/batchExportSuccess/sendBatchExportSuccessEmail.ts (Lines 18-53)
    • packages/shared/src/server/services/email/batchExportSuccess/BatchExportSuccessEmailTemplate.tsx (Lines 24-84)

Signature

type SendBatchExportSuccessParams = {
  env: Partial<
    Record<"EMAIL_FROM_ADDRESS" | "SMTP_CONNECTION_URL", string | undefined>
  >;
  receiverEmail: string;
  downloadLink: string;
  userName: string;
  batchExportName: string;
};

export const sendBatchExportSuccessEmail = async ({
  env,
  receiverEmail,
  downloadLink,
  userName,
  batchExportName,
}: SendBatchExportSuccessParams): Promise<void>;

Import

import { sendBatchExportSuccessEmail } from "@langfuse/shared/src/server";

I/O Contract

Inputs

Name Type Required Description
env "SMTP_CONNECTION_URL", string | undefined>> Yes An object containing the email configuration environment variables. If either EMAIL_FROM_ADDRESS or SMTP_CONNECTION_URL is missing, the function returns without sending.
receiverEmail string Yes The email address of the user who initiated the export.
downloadLink string Yes The signed URL for downloading the export file. Embedded in the email as the "Download Export" button href.
userName string Yes The name of the user, used in the email greeting ("Hello {userName}"). May be an empty string if the user has no name set.
batchExportName string Yes The name of the export as specified during creation. Displayed in the email body in monospace font to help the user identify the export.

Outputs

Name Type Description
(void) Promise<void> Resolves when the email is sent successfully or when sending is skipped (missing config). Does not throw on failure -- errors are logged internally. The calling code does not receive feedback on whether the email was actually delivered.

Usage Examples

Sending notification after successful export

import { sendBatchExportSuccessEmail } from "@langfuse/shared/src/server";
import { env } from "../../env";

// After uploading export file and updating DB record to COMPLETED:
const user = await prisma.user.findFirst({
  where: { id: jobDetails.userId },
});

if (user?.email) {
  await sendBatchExportSuccessEmail({
    env,
    receiverEmail: user.email,
    downloadLink: signedUrl,
    userName: user.name || "",
    batchExportName: jobDetails.name,
  });
}

Behavior when SMTP is not configured

// When EMAIL_FROM_ADDRESS or SMTP_CONNECTION_URL is missing:
await sendBatchExportSuccessEmail({
  env: {
    EMAIL_FROM_ADDRESS: undefined,
    SMTP_CONNECTION_URL: "smtp://localhost:587",
  },
  receiverEmail: "user@example.com",
  downloadLink: "https://s3.amazonaws.com/...",
  userName: "Jane",
  batchExportName: "Traces Export",
});
// Logs: "Missing environment variables for sending email."
// Returns without sending -- no error thrown

Email template rendering

// The template is rendered server-side using @react-email/render:
import { render } from "@react-email/render";
import { BatchExportSuccessEmailTemplate } from "./BatchExportSuccessEmailTemplate";

const html = await render(
  BatchExportSuccessEmailTemplate({
    receiverEmail: "user@example.com",
    downloadLink: "https://storage.example.com/exports/file.csv?sig=...",
    userName: "Jane Doe",
    batchExportName: "Traces Export 2026-02-14",
  }),
);

// html contains the full email HTML with:
// - Langfuse logo
// - "Your data export is ready" heading
// - "Hello Jane Doe" greeting
// - Export name "Traces Export 2026-02-14" in monospace
// - "Download Export" button linking to the signed URL
// - Footer with recipient email

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment