Sending examples

Send with Node.js

Send email from a Node.js or TypeScript project using the Sendtern SDK.

Prerequisites

  • A Sendtern API key stored as SENDTERN_API_KEY
  • Node.js 18 or newer
  1. 1

    Install the SDK

    Run this command in your project.

    1npm install sendtern
    
  2. 2

    Send an email

    Create send.mjs and run it with node send.mjs.

    1import { Sendtern } from 'sendtern';
    2
    3const client = new Sendtern(process.env.SENDTERN_API_KEY);
    4const result = await client.emails.send({
    5  "from": "Acme <hello@mail.example.com>",
    6  "to": "you@example.com",
    7  "subject": "Welcome to Acme",
    8  "text": "Thanks for signing up."
    9});
    10console.log(result.id);
    
  3. 3

    Check the response

    A successful request returns 200 OK with the email id. Use it to look the email up later.

    1{
    2  "id": "47be30ca-24b7-48fb-b35d-ff287b89e66d"
    3}
    

Replace the example sender with an address on your verified domain.

Questions sent for AI answers are processed by DeepSeek. Leave out credentials and personal data.