Sign inGet Started

Node.js SDK

Send email with RedwoodJS

Use Parcel Wing from RedwoodJS API-side services and functions while keeping API keys out of your web side bundle.

Install the SDK

The official SDK is published as @parcelwing/node.

Terminal

npm install @parcelwing/node

API-side service

Put the Parcel Wing client on the API side, then call this service from GraphQL resolvers, jobs, functions, or other trusted server code.

api/src/services/mail/mail.ts

import { ParcelWing, ParcelWingError } from "@parcelwing/node";
 
const parcelWing = new ParcelWing({
apiKey: process.env.PARCEL_WING_API_KEY!,
});
 
export async function sendWelcomeEmail({
email,
firstName = "friend",
}: {
email: string;
firstName?: string;
}) {
try {
const [message] = await parcelWing.emails.send({
from: "Acme <[email protected]>",
to: email,
template_alias: "welcome_email",
template_params: {
first_name: firstName,
},
});
 
return { id: message?.id };
} catch (error) {
if (error instanceof ParcelWingError) {
throw new Error(
"Parcel Wing request " +
(error.requestId ?? "unknown") +
" failed: " +
error.code,
);
}
 
throw error;
}
}

Serverless function

Expose a small API function when your web side needs to submit a contact form, invite, or onboarding email request.

api/src/functions/sendWelcome.ts

import type { APIGatewayEvent, Context } from "aws-lambda";
import { sendWelcomeEmail } from "src/services/mail/mail";
 
export const handler = async (event: APIGatewayEvent, _context: Context) => {
const body = JSON.parse(event.body ?? "{}");
 
const result = await sendWelcomeEmail({
email: body.email,
firstName: body.firstName,
});
 
return {
statusCode: 200,
headers: { "content-type": "application/json" },
body: JSON.stringify(result),
};
};

Production notes

  • Store PARCEL_WING_API_KEY in server/API-side environment variables.
  • Validate inputs before calling service methods that send email.
  • Use saved templates for repeatable onboarding, invite, and receipt emails.