0.1.6 • Published 3 months ago

nodemailer-sequelize-queue v0.1.6

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 months ago

Nodemailer sequelize queue

Npm package

This package allows to queue email and process it later by schedule using Nodemailer for sending mails, Sequelize for save queue to database and Node cron for scheduling.

Getting Started

Install nodemailer-sequelize-queue using npm:

npm i nodemailer-sequelize-queue

or use yarn

yarn add nodemailer-sequelize-queue

Usage

  1. Create NodemailerSequelizeQueue instance
import NodemailerSequelizeQueue from 'nodemailer-sequelize-queue'

const dbCredentials = {
  // See https://www.npmjs.com/package/sequelize for more options
  config: {
    username: process.env.db_username || '',
    password: process.env.db_password || '',
    database: process.env.db_database || '',
    host: process.env.db_host || '',
    dialect: 'mysql' as any,
  },
  // Alternatively you can use existing sequelize instance
  // sequelize: SequelizeInstane
}
// See https://www.npmjs.com/package/nodemailer for more options
const smtpCreds = {
  host: process.env.smtp_host,
  port: process.env.smtp_port ? process.env.smtp_port : 465,
}

const queue = new NodemailerSequelizeQueue(
  dbCredentials,
  smtpCreds,
  {
  // See https://www.npmjs.com/package/nodemailer for more expression options
  expression: '*/1 * * * *',
  // If -1, will try infinite times
  maxAttempts: 2,
  }
)
  1. Run cron schedule for sending mail (Only one time in root of the system)
queue.initScheduler()
  1. Add mail to queue
queue.queueMail({
  email_from: 'test@gmail.com',
  email_to: 'test@gmail.com',
  subject: 'test subject',
  html: 'test message',
  attachments: [
    {
      // Not required (see Nodemailer filename prop)
      filename: 'file.jpg',
      // Local or remote url (see Nodemailer path prop)
      path: 'https://picsum.photos/id/237/200/300',
    },
    ]
})

License

The MIT License (MIT). Please see License File for more information.

0.1.4

3 months ago

0.1.6

3 months ago

0.1.5

3 months ago

0.0.20

1 year ago

0.0.22

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.3

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

1 year ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago