Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.