Service that sends notification emails, from a Firebase queue.
Service that sends notification emails, from a Firebase queue.
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:
I wrote this script for the “Clear” project.
npm install
;run.sh
file;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);run.sh
file;EMAIL_FROM
and EMAIL_TO
fields of run.sh
;run.sh
(without the --dry-run
argument) => you should receive that email within 5 minutes, given your Sendgrid account was provisionned.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.FIREBASE_API_KEY
: API key of your Firebase DatabaseFIREBASE_DATA_URL
: URL of your Firebase Database (with .firebaseio.com
suffix)SENDGRID_API_KEY
: API key provided by Sendgrid after creating your accountEMAIL_FROM
: Email address from which daily emails will be sentEMAIL_TO
: Email address of the recipient (i.e. you, I guess)FIREBASE_DATA_PATH
: Path in which your emails are stored. Default value: /
.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.