Skip to content

Documentation

Migrate from SendGrid.

The request body is flatter and the response carries an ID. Here is the send call before and after, then what carries over and what to check.

The send call, before and after

Before, with SendGrid's v3 mail send API (see SendGrid's docs for your library version):

send.js
import sgMail from "@sendgrid/mail";
​
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
await sgMail.send({ from: "ada@yourdomain.com", to: "you@example.com", subject: "Hello", html: "<p>It works.</p>" });

After, with Mailtruss:

send.ts
import { MailClient } from "mailtruss";
​
const mail = new MailClient({ apiKey: process.env.MAILTRUSS_API_KEY! });
const { id } = await mail.emails.send({ from: "ada@yourdomain.com", to: "you@example.com", subject: "Hello", html: "<p>It works.</p>" });

The main change is the body: SendGrid nests recipients in personalizations and the sender in an object, and takes the content as a list of typed parts. Mailtruss takes from, to, subject, html and text as plain fields. SendGrid answers a send with 202 and no body; Mailtruss returns the new email's id, which you can use to fetch its delivery trace. Other languages are under send email by language.

If you send over SMTP

Apps that use SendGrid's SMTP relay only need new settings. SendGrid's relay uses the literal username apikey with an API key as the password. Mailtruss takes any username with an API key as the password:

SMTP settings
host: smtp.sendgrid.net
port: 587
username: apikey
password: <your SendGrid API key>

Details and framework examples are on the SMTP page and in the integration guides.

What maps to what

  • Several recipients: to, cc and bcc take lists. To send different messages to different people, use POST /api/v1/emails/batch.
  • Dynamic templates: a Mailtruss template is sent by ID with a variables object, and only the published version is ever sent. See Sending.
  • Categories and custom arguments: roughly tags, which are name and value pairs you can filter by.
  • Unsubscribe groups: topics, which people can switch on or off from the unsubscribe page without leaving everything.
  • Scheduling: scheduled_at takes an ISO 8601 time.
  • Attachments: base64 content with a filename.
  • Marketing contacts and campaigns: contacts, segments and broadcasts.

Webhooks

SendGrid signs its event webhook with its own scheme, so verification code has to change. Mailtruss signs webhooks with the Standard Webhooks scheme, and the client libraries include a verifyWebhook helper. Events have different names (email.delivered, email.bounced, email.complained), so map them in your handler. See Webhooks.

A safe order to switch

  1. Create an account and verify your sending domain (DNS records). Verification here is separate from SendGrid's, and the records differ.
  2. Create a key and send a test to delivered@mailtruss.test, so nothing reaches a real inbox.
  3. Change the client, the key and the request body in one place in your code.
  4. Point your webhook handler at the new signing secret and event names, then send real mail.
  5. Keep SendGrid active for a few days while you watch the first real sends, then switch it off.

Comparing costs first? See Mailtruss vs SendGrid, which uses SendGrid's own published prices. Mailtruss's are on the pricing page.

Last updated

Something wrong or unclear on this page?

Report an issue