Coder Social home page Coder Social logo

nodemailer-sequelize-queue's Introduction

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: '[email protected]',
  email_to: '[email protected]',
  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.

nodemailer-sequelize-queue's People

Contributors

alexsanteenodev avatar

Stargazers

Jin Yao avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.