Skip to main content

Email Template

Carrier is a micro service to manage Email notification templates. You can easily create or update your email templates on it, and it will convert simple HTML texts into MJML-generated Email. Once you provided your SendGrid, Carrier will issue a carrierToken for your service to call and send the generated email with certain data payload.

How to use it?

Setup and prepare the template

  1. Get the SendGrid API key from
  2. Go to Create an account if you do not have one. And place the SendGrid API key into the form and submit.
  3. Upload your logo as well
  4. Go to and click "New Template" to create a new template.

Call Carrier to send Email

  1. Grab or set the carrierToken from
  2. Create a carrier client in your server's clients / gateways directory
import Axios, { AxiosInstance } from "axios";
import { logger } from "onefx/lib/integrated-gateways/logger";

const sendOperation = `
mutation Send(
$templateId: String!
$email: String!
$idempotencyKey: String!
$payload: JSONObject
) {
templateId: $templateId
email: $email
idempotencyKey: $idempotencyKey
payload: $payload

type SendArgs = {
templateId: string;
email: string;
idempotencyKey: string;
payload: Record<string, unknown>;

export type CarrierOpts = {
timeout: number;
endpoint: string;
token: string;

export class Carrier {
private axios: AxiosInstance;

constructor(opts: CarrierOpts) {
this.axios = Axios.create({
baseURL: opts.endpoint,
timeout: opts.timeout,
headers: {
authorization: `Bearer ${opts.token}`,

async send(sendArgs: SendArgs): Promise<void> {
try {
const resp = await"/", {
query: sendOperation,
variables: sendArgs,
if ( && {
logger.error(`carrier failed to send notification`,;
} catch (err) {
logger.error(`carrier failed to send notification`, err);
throw err;

Then instantiate the client and send email

const carrier = new Carrier({
endpoint: "",
timeout: 5000,
token: "carrier_TODO",

// use login_email_token template with the data payload having loginUrl
await carrier.send({
templateId: "login_email_token",
email: "",
idempotencyKey: "yo",
payload: {
loginUrl: "",