Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created May 1, 2013 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawsontoth/5494198 to your computer and use it in GitHub Desktop.
Save dawsontoth/5494198 to your computer and use it in GitHub Desktop.
SMTP to colored terminal NodeJS app.
/*
Drop this in an app.js, customize the port, and:
> npm install simplesmtp cli-color
> node app.js
*/
try {
var port = 10025,
simplesmtp = require('simplesmtp'),
clc = require('cli-color'),
smtp = simplesmtp.createServer();
smtp.listen(port);
smtp.on("startData", function (connection) {
connection.__data = '';
});
smtp.on("data", function (connection, chunk) {
connection.__data += chunk;
});
smtp.on("dataReady", function (connection) {
var data = connection.__data,
subject = data.split('Subject: ')[1].split('\n')[0].trim(),
body = data
.split('Content-Transfer-Encoding: ')[1]
.split('\n').slice(1).join('\n')
.replace(/=3D/g, '=')
.replace(/=22/g, '"')
.replace(/=\r\n/g, '')
.trim();
console.log('\n');
console.log(clc.blackBright('From ') + clc.white(connection.from)
+ clc.blackBright(' to ') + connection.to.map(function (a) {
return clc.white(a);
}).join(clc.blackBright(', ')));
console.log(clc.blackBright('Subject ') + clc.white(subject));
console.log(body.replace(/(<[^<>]+?>)/ig, clc.cyan('$1')));
});
}
catch (err) {
console.log(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment