Skip to content
API Reference
Transactional emails

Sending transactional emails

Sending transactional emails with Plunk unlocks another layer of connectivity.

POST /v1/send

Used to send transactional emails to a single recipient or multiple recipients at once. Transactional emails are programmatically sent emails that are considered to be part of your application's workflow. This could be a password reset email, a billing email or other non-marketing emails.

Authorization

This endpoint can only be accessed with a secret key.

Example

await fetch('https://api.useplunk.com/v1/send', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer SECRET_KEY", // Put your API key here
    },
    body: JSON.stringify({
        "to": "hello@useplunk.com",
        "subject": "Please confirm your email",
        "body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
    }),
});

Customizing from address and name

By specifying the from and name fields, you can customize the from address and name of the email. If you don't specify these fields, the default address and name configured in your project settings will be used.

💡

Using a custom from address is only available to projects with a verified domain. Once you have a verified domain, any address of that domain can be used as the from address.

await fetch('https://api.useplunk.com/v1/send', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer SECRET_KEY", // Put your API key here
    },
    body: JSON.stringify({
        "from": "billing@useplunk.com",
        "name": "Plunk Billing",
        "to": "hello@useplunk.com",
        "subject": "Welcome!",
        "body": "Hello",
    }),
});

Using Markdown

It is possible to use Markdown when sending a transactional email. Plunk will automatically apply the same styling as the email templates you make in the editor.

Specify the type field as markdown to use Markdown.

await fetch('https://api.useplunk.com/v1/send', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer SECRET_KEY", // Put your API key here
    },
    body: JSON.stringify({
        "type": "markdown",
        "to": "hello@useplunk.com",
        "subject": "Welcome!",
        "body": "# Hello",
    }),
});

Using React Email

Plunk's transactional email API is fully compatible with React Email (opens in a new tab). React Email is a library that allows you to write email layouts using React components. It abstracts away the responsiveness and cross-client compatibility issues, so you can focus on the content and style of your emails.

Install dependencies

When using React Email, you can use the Plunk Node.js SDK. Install it and React Email using your package manager of choice:

npm install @plunk/node @react-email/render

Create a React Email component

Use React Email to create a reusable email template.

import * as React from 'react';
import { Html } from '@react-email/html';
import { Button } from '@react-email/button';
 
export default function Email(props) {
  const { url } = props;
 
  return (
    <Html lang="en">
      <Button href={url}>Click me</Button>
    </Html>
  );
}

Convert and send

Use React Email's render function to convert your React component to HTML, and send it using the Plunk Node.js SDK.

import Plunk from '@plunk/node';
import { render } from '@react-email/render';
import { Email } from './email';
 
const plunk = new Plunk("YOUR_API_KEY");
 
const body = render(<Email url="https://example.com" />);
 
const success = await plunk.emails.send({
    to: "hello@useplunk.com",
    subject: "Hello world",
    body,
});
Last updated on June 5, 2023