Integrations
Node.js
Use IndiePitcher with your Node.js apps
Introduction
- Easily integrate IndiePitcher with your Node.js apps using the official SDK
- All examples can be found inside the sample app
Markdown
Here’s an example Next.js page that sends a markdown email using the IndiePitcher SDK
'use server'
import { IndiePitcher } from "indiepitcher";
export async function sendSimpleMarkdownEmail(): Promise<string | Error> {
if (!process.env.INDIEPITCHER_API_KEY) {
return new Error("Create .env.local file containing INDIEPITCHER_API_KEY. You can get the key by signing up at https://indiepitcher");
}
try {
const indiePitcher = new IndiePitcher(process.env.INDIEPITCHER_API_KEY!);
await indiePitcher.sendEmail({ to: "petr@indiepitcher.com", subject: "Hello", body: "Hello, **World**!", bodyFormat: "markdown" });
return "Email sent!";
} catch (error) {
return error as Error;
}
}
React Email
Here’s an example Next.js page that sends personalized email using ReactEmail.
"use server";
import { render } from "@react-email/components";
import { IndiePitcher } from "indiepitcher";
import * as React from "react";
import { Html, Button } from "@react-email/components";
function PersonalizedEmail(props: { url: any; }) {
const { url } = props;
return (
<Html lang="en">
Hi {'{{firstName|default: "there"}}'}, <Button href={url}>Click me</Button> or <Button href={'{{unsubscribeURL}}'}>Unsubscribe</Button>
</Html>
);
}
export async function sendPersonalizedReactHtmlEmail(): Promise<
string | Error
> {
if (!process.env.INDIEPITCHER_API_KEY) {
return new Error(
"Create .env.local file containing INDIEPITCHER_API_KEY. You can get the key by signing up at https://indiepitcher"
);
}
try {
const indiePitcher = new IndiePitcher(process.env.INDIEPITCHER_API_KEY!);
const emailHtml = await render(
<PersonalizedEmail url="https://indiepitcher.com" />
);
await indiePitcher.addContact({
email: "petr@indiepitcher.com",
name: "Petr Pavlik",
updateIfExists: true,
ignoreListSubscriptionsWhenUpdating: true,
subscribedToLists: ["test_list_1", "test_list_2"],
});
await indiePitcher.sendEmailToContact({
contactEmail: "petr@indiepitcher.com",
subject: "Hello react email!",
body: emailHtml,
bodyFormat: "html",
list: "test_list_1",
});
return "Email sent!";
} catch (error) {
return error as Error;
}
}
On this page
Assistant
Responses are generated using AI and may contain mistakes.