Created
April 2, 2020 13:33
-
-
Save geobabbler/1abcc59b8d713399885362f87cd0db67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var PGPubsub = require('pg-pubsub'); | |
var nodemailer = require('nodemailer'); | |
var pubsubInstance = new PGPubsub('postgres://password:user@host:port/database'); // don't hard code this in real life. get it from a config or environment variable | |
var transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: "email@gmail.com", // don't hard code this in real life. get it from a config or environment variable | |
pass: "complex_gmail_password" // don't hard code this in real life. get it from a config or environment variable | |
} | |
}); | |
pubsubInstance.addChannel('jhucounty', function (channelPayload) { | |
var msg = channelPayload.properties.label + ": " + channelPayload.properties.confirmed; | |
var mailOptions = { | |
from: "email@gmail.com", // don't hard code this in real life. get it from a config or environment variable | |
to: 'recipient@some.tld', // don't hard code this in real life. get it from a config or environment variable | |
subject: 'COVID-19 update for ' + channelPayload.properties.label, | |
text: msg | |
}; | |
transporter.sendMail(mailOptions, function(error, info){ | |
if (error) { | |
console.log(error); | |
} else { | |
console.log('Email sent: ' + info.response); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment