@anxolin/mail
v0.1.2
Published
Simple mail repository
Downloads
5
Readme
node-mail
Basic mail sender
Implement a repository for easily sending mails.
It uses nodemailer
and all methods return promises.
Usage
First install dependencies:
yarn add @anxolin/mail --save # npm install @anxolin/mail --save
Then, use it:
const mailSender = require('@anxolin/mail')({
user: 'your-user',
password: 'your-password',
host: 'your-password'
})
// Verify the connection
mailSender
.verify()
.then(success => console.log('Mail connection result: %s', success))
.catch(console.error)
mailSender
.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Hi there ✔',
text: 'How are you doing?',
html: 'How are <b>you</b> doing?'
})
.then(mailInfo => console.log('Mail sent: %s', mailInfo.messageId))
.catch(console.error)
Config
const mailSender = require('@anxolin/mail')(config)
Where config
may contain:
| Parameter | Required | Description |
| ----------|:--------:| -----:|
| user | Yes | User for the mail authentication |
| password | Yes | Password for the mail authentication |
| host | Yes | Mail server host |
| port | No. Default 587
| Port |
| secure | No. Default false
| Secure |
| requireTLS | No. Dedault true
| Require TLS |
Send a test mail
To test, execute:
yarn install
# Execute
[email protected] \
MAIL_PASSWORD=your-pass-here \
HOST=mail.example.com \
[email protected] \
[email protected] \
SUBJECT="Hi there ✔" \
TEXT="How are you doing?" \
HTML="How are <b>you</b> doing?" \
yarn send-mail
Create a .env file
A simpler approach to execute the mail sender is to create a .env
file:
[email protected]
MAIL_PASSWORD=your-pass-here
HOST=mail.example.com
[email protected]
[email protected]
SUBJECT="Hi there ✔"
TEXT="How are you doing?"
HTML="How are <b>you</b> doing?"
yarn send-mail
Execute the tests
yarn test