Skip to main content

Mailing

Introduction

CairJS use nodemailer, to send emails.

Install packages

npm install @cairjs/core @cairjs/mailing

Configuration

Add and complete in your .env file:

MAIL_FROM=example@domain.com
MAIL_URL=<protocol>://<username>:<password>@<host>

Use

import {sendEmail} from '@cairjs/mailing

sendEmail({
to: email,
subject: 'This is subject',
text: 'This is text body',
html: `<html>
<body>
<p>content</p>
</body>
</html>`
})

Custom transporter

Transport

Syntax

sendEmail(options, transporter)

Example using Custom transporter

import { sendEmail, createTransport } from '@cairjs/mailing'

const MailURL = '<protocol>://<username>:<password>@<host>'
const transporter = createTransport(MailURL)

const options = {
from: 'from@domain.com',
to: 'to@domain.com',
subject: 'This is subject',
text: 'This is text body'
}

sendEmail(options, transporter)