eviso-email v1.0.17
EVISO NODE MAILER
# Documentation
StackEdit stores your files in your browser, which means all your files are automatically saved locally and are accessible offline!
Install
npm install eviso-email
OR
yarn add eviso-email
SETUP PACKAGE
This package comes with DB (MYSQL) , Mailgun API and SMTP integration. For that you have to define the following variables in your .env
EVISO_MAIL_SMTP_HOST="smtp.foobar.com"
EVISO_MAIL_SMTP_PORT=587
EVISO_MAIL_SMTP_USER="foo@bar.it"
EVISO_MAIL_SMTP_PWD="userEmail password"
EVISO_MAIL_SMTP_SECURE=false
EVISO_MAIL_SMTP_TLS=false
EVISO_MAIL_MAILGUN_APIKEY="MAILGUN API KEY"
EVISO_MAIL_MAILGUN_DOMAIN="MAILGUN DOMAIN"
EVISO_MAIL_DB_HOST="DB HOST",
EVISO_MAIL_DB_PORT="DB PORT"
EVISO_MAIL_DB_USER="DB USER" // Must have permissions to read and write
EVISO_MAIL_DB_PASSWORD="DB_PWD"
EVISO_MAIL_DB_DATABASE="DB NAME" //In our case it is recommended to use the Report schema
Setup database tables
To ensure the standard structure of the tables, this package has already integrated two migrations to create the tables. This command should be run in the root of the project, not outside. sequelize db:migrate
After these steps the package is ready for use. :)
Getting Started
const {EvisoMail} = required('eviso-email');
Methods
Inside the EvisoMail class we have methods to deal specifically with the different integrations
SMTP
sendEmailSMTP({to,message}: IMessageDTO,emailID?:string)
This method is designed to handle two scenarios - send a new email or resend the email (create or update) We can use it in the following ways:
// to send a new email
EvisoMail.sendEmailSMTP({
'to':{email:'foo@bar.com',name:'foo'},
'message':{subject: 'subject foo bar', body: 'html body'} )
//to resend email
EvisoMail.sendEmailSMTP({
'to':{email:'foo@bar.com',name:'foo'},
'message':{subject: 'subject foo bar', body: 'html body'}, emailID)
Schedule SMTP delivery
This method allows you to schedule the sending of e-mails. It can be integrated into a single or bulk logic. The date must be in the indicated format so that the APP can send the schedules on the desired day and time.
EvisoMail.schedulingEmailSMTP({
'to':{email:'foo@bar.com',name:'foo'},
'message':{subject: 'subject foo bar', body: 'html body',}},
'yyyy-MM-dd hh:mm'
)
Mailgun Integration
The integration allows you to send e-mails and check their sending status.
EvisoMail.sendEmailMailgun(
{
'to':{email:'foo@bar.com',name:'foo'},
'message':{subject: 'subject foo bar', body: 'html body',}
},
{
title: 'title event for mailgun',
email: 'sender email '
}
)
Although there is a routine that queries and updates the status of the emails sent by the API, the method is available if you want to use a custom routine.
EvisoMail.statusMailGun()
This method will query all the emails sent by mailgun in pendig state and update their status in the DB.
Database
The package installs two tables:
mail_sender
This table records all email sends, with all the projected promenors like email status, sender, receiver. Subject, body, env, etc. | id | primary KEY - BIGINT - autoincrement | | from | varchar 255 - not allowed null | | to | varchar 255 - not allowed null | | cc | varchar 255 - allowed null | | bcc | varchar 255 - allowed null | | subject | varchar 255 - not allowed null | | tags | varchar 255 - allowed null | | status | varchar 255 - not allowed null | | env | varchar 255 - not allowed null | | body | mediumtext - not allowed null | | type | varchar 255 - not allowed null | | message_id | varchar 255 - not allowed null | | request_datetime | datetime - not allowed null | | response | mediumtext - not allowed null | | createdAt | datetime | | updatedAt** | datetime |
EXEMPLE
mail_qeue
This table records all scheduled emails, when the job runs it queries this table and all processes that are in pending are processed on the scheduled qeue_date.
| id | primary KEY - BIGINT - autoincrement | | qeue_date | datetime - not allowed null | | status | varchar 255 - not allowed null | | email_id | int - not allowed null | | createdAt| datetime | | updatedAt | datetime |