#! /usr/bin/env node const config = require('./config.json'); const dash_button = require('node-dash-button'); const nodemailer = require('nodemailer'); // TODO: accept and register an array of button MACs const dash = dash_button(config.button.id); const util = require('util'); const _ = require('lodash'); const when = require('when'); // create reusable transporter object using the default SMTP transport let transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: config.gmail.user, pass: config.gmail.pass } }); // setup email data with unicode symbols let mailOptions = { from: config.message.from, // sender address to: config.message.to.toString(), // list of receivers subject: config.message.subject, // Subject line text: new Date().toISOString(). replace(/T/, ' '). // replace T with a space replace(/\..+/, '') // delete the dot and everything after }; console.log('waiting for dash button to be pressed...'); dash.on('detected', () => { console.log('Dash button detected!'); transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.log(error); } console.log('Message %s sent: %s', info.messageId, info.response); }); // for now we can ignore the promise as it handles any logging and we've no need to care about when it resolves or rejects });