GithubHelp home page GithubHelp logo

adrienjoly / notif-mailer Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 29 KB

Service that sends notification emails, from a Firebase queue.

JavaScript 93.62% Shell 6.38%
firebase-database sendgrid heroku cronjob queue service worker

notif-mailer's Introduction

notif-mailer

Service that sends notification emails, from a Firebase queue.

What it does

After deploying and setting up this script to your favorite server (e.g. a Heroku instance), the run.js script is meant to be run every 10 minutes, and will:

  1. Fetch the pending notifications from the associated Firebase database;
  2. Email and remove the expected notifications (due from now).

I wrote this script for the "Clear" project.

Setup

  1. Clone this repository locally, then npm install;
  2. Create a Firebase database => fill your Firebase credentials in the run.sh file;
  3. Run npm test locally, it will store a sample notification in your Firebase database, and display the corresponding notification email that would be sent (using --dry-run toggle);
  4. Create a Sendgrid account => fill the API credentials in the run.sh file;
  5. Then, fill the EMAIL_FROM and EMAIL_TO fields of run.sh;
  6. When the test works, run run.sh (without the --dry-run argument) => you should receive that email within 5 minutes, given your Sendgrid account was provisionned.
  7. Now you can push all that to your favorite web server or hosting service, and configure it so that run.sh is run every day, at the time of your choice. If, like me, you decide to use Heroku, you can use the Scheduler addon. Otherwise, a cron script should work.

Required environment variables

  • FIREBASE_API_KEY: API key of your Firebase Database
  • FIREBASE_DATA_URL: URL of your Firebase Database (with .firebaseio.com suffix)
  • SENDGRID_API_KEY: API key provided by Sendgrid after creating your account
  • EMAIL_FROM: Email address from which daily emails will be sent
  • EMAIL_TO: Email address of the recipient (i.e. you, I guess)

Optional environment variables

  • FIREBASE_DATA_PATH: Path in which your emails are stored. Default value: /.

Model of emails in Firebase

When FIREBASE_DATA_PATH is set as /emailNotifs, the test-sample-emails will populate your Firebase Database like this:

{
  "emailNotifs" : {
    "-Kh2jS_-AQvh-_GgUDyh" : {
      "subject" : "fake email 1",
      "text" : "should be sent now",
      "when" : 1491490167102
    },
    "-Kh2jSs_htKipIGCIVL7" : {
      "subject" : "fake email 2",
      "text" : "should be sent in 5 seconds or more",
      "when" : 1491490172102
    }
  }
}

The when property of each email object is a date-time serialized in milliseconds.

notif-mailer's People

Contributors

adrienjoly avatar

Stargazers

Dashon 'DJ' Hawkins avatar Saad Elbeleidy avatar

Watchers

 avatar James Cloos avatar  avatar

notif-mailer's Issues

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.