Skip to content

Send email using SMTP

Steve Lebleu edited this page Apr 25, 2026 · 8 revisions

This section describes how to send emails using SMTP relay through concrete examples.

> Table of contents

> Configure your SMTP transporter

In cliamrc.js, define your transporter like this:

{
  "id": "hosting-smtp",
  "auth": {
    "username": "USERNAME",
    "password": "ÂĻPASSWORD"
  },
  "options": {
    "host": "mail.host.com",
    "port": 587,
    "secure": true
  }
}

> Send email

> Using your own template

To use your own templates, you pass content property with adapted input (text/html at least required):

import { Cliam } from 'cliam';

const payload = {
  transporterId: 'hosting-smtp',
  meta: {...},
  content: [
    { type: 'text/html', value: '<html><p>Email content</p></html>' }
  ]
};
  
Cliam.mail('user.welcome', payload)
  .then(res => {
    console.log('Email has been delivered: ', res);
  })
  .catch(err => {
    console.log('Error while mail sending: ', err)
  });

The content property accept an object array as value:

  • Min 1 object with type text/html.
  • Max 2 objects (type text/html and type text/plain).
  • Type text/plain is optionnal and will be generated from text/html if not present.

> Using cliam template

Adapt your input using a data property and a valid transactional event key:

import { Cliam } from 'cliam';

const payload = {
  transporterId: 'hosting-smtp',
  meta: {...},
  data: {
    user: { 
      username: 'John Doe',
      email: 'john.doe@example.com'
    },
    message: 'Hi John ! \n\n Welcome on board !',
    cta: {
      label: 'Go to your profile',
      link: 'https://www.example.com/profile'
    }
  }
};
  
Cliam.mail('user.welcome', payload)
  .then(res => {
    console.log('Email has been delivered: ', res);
  })
  .catch(err => {
    console.log('Error while mail sending: ', err)
  });

⚠ïļ Cliam templates are only available for pre-defined transactions. See transactions definitions to know more about available transactions and associated inputs.

Discuss on Slack

Clone this wiki locally