Created
May 3, 2012 15:17
-
-
Save michaelcox/2586403 to your computer and use it in GitHub Desktop.
Command Line nodejs App For Sending Test Emails
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
#!/usr/bin/env node | |
var program = require('commander'); | |
var email = require("mailer"); | |
program | |
.version('0.0.1') | |
.option('-s, --subject <text>', 'subject line of email') | |
.option('-b, --body <text>', 'body area of email') | |
.option('-r, --recipient <email>', "recipient's email address") | |
.option('-a --showAll', "output recipient, subject, and body as specified") | |
.parse(process.argv); | |
if (program.showAll) { | |
console.log("Recipient: " + program.recipient); | |
console.log("Subject: " + program.subject); | |
console.log("Body: " + program.body); | |
} | |
if (program.recipient && program.subject && program.body) { | |
email.send({ | |
host : "ENTER SMTP HOST HERE", | |
port : "ENTER SMTP PORT HERE", | |
domain : "ENTER DOMAIN HERE", | |
to : program.recipient, | |
from : "ENTER FROM ADDRESS HERE", | |
subject : program.subject, | |
body: program.body, | |
authentication : "login", | |
username : 'ENTER USERNAME HERE', | |
password : 'ENTER PASSWORD HERE', | |
headers : {"X-Sample-Header": "ABC123YOUANDME"} | |
}, | |
function(err, result) { | |
if (err) { | |
console.log(err); | |
} else if (result === true) { | |
console.log('Email sent successfully!'); | |
} else { | |
console.log("Result: " + result); | |
} | |
} | |
); | |
} else { | |
console.log("ERROR: You must specify a recipient, subject line, and email body."); | |
} |
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
{ | |
"name": "email-test", | |
"private": true, | |
"version": "0.0.1", | |
"description": "a simple smtp test application", | |
"keywords": [ | |
"email" | |
], | |
"main": "email", | |
"engines": { | |
"node": ">= 0.4.x < 0.7.0" | |
}, | |
"dependencies": { | |
"commander": "~0.6.0", | |
"mailer": "~0.6.7" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment