1.0.17 • Published 3 years ago

eviso-email v1.0.17

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

EVISO NODE MAILER

enter image description here

# 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

enter image description here

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 |

Exemple

enter image description here

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago