Skip to content

Instantly share code, notes, and snippets.

@ivan-loh
Last active December 30, 2015 05:59
Show Gist options
  • Select an option

  • Save ivan-loh/7786742 to your computer and use it in GitHub Desktop.

Select an option

Save ivan-loh/7786742 to your computer and use it in GitHub Desktop.
need a quick and dirty way to send files from offsite server ? node to the rescue
var program = require('commander');
var nodemailer = require('nodemailer');
/**
* args
**/
program
.version('0.0.1')
.option('-n, --name [value]', 'Name of the attachment file')
.option('-f, --file [value]', 'Backup File to be sent')
.parse(process.argv);
if (program.file === undefined) {
console.log('Backup File not specified');
return;
}
/**
* mailing parameters.
**/
var transport = nodemailer.createTransport('SMTP', {
host : 'smtp.zoho.com',
secureConnection: true,
port: 465,
auth: { user: 'email goes here', pass: 'fake password for gist' }
});
var mailOptions = {
from: 'Sender email',
to: 'recipient',
subject: 'Backup ' + Date(),
attachments: [ { fileName: program.name, filePath: program.file } ]
};
/**
* Wheeeee, here we go
**/
transport.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
process.exit(1);
} else {
console.log('Message sent:' + response.message);
process.exit(0);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment