Last active
December 30, 2015 05:59
-
-
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
This file contains hidden or 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 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