Repository navigation
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.
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
}
}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/htmland typetext/plain). - Type
text/plainis optionnal and will be generated fromtext/htmlif not present.
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)
});