Mailing
Introduction
CairJS use nodemailer, to send emails.
Install packages
- npm
- Yarn
npm install @cairjs/core @cairjs/mailing
yarn add @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
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)