parse incoming messages and pass them along to the endpoint
This commit is contained in:
parent
13852758cd
commit
fb678f0afe
@ -2,6 +2,7 @@ var squabble = require("squabble").createParser(),
|
||||
smtp = require("smtp-protocol"),
|
||||
http = require("request"),
|
||||
readFile = require("fs").readFileSync,
|
||||
MailParser = require("mailparser").MailParser,
|
||||
args,
|
||||
tlsTokens,
|
||||
serverOpts = {};
|
||||
@ -13,6 +14,7 @@ squabble.shortOpts().longOpts().stopper()
|
||||
|
||||
// parse arguments
|
||||
args = squabble.parse();
|
||||
serverOpts.endpoint = args.named.ENDPOINT;
|
||||
if (args.named["--tls"]) {
|
||||
tlsTokens = args.named["--tls"].split(":");
|
||||
switch (tlsTokens.length) {
|
||||
@ -37,12 +39,24 @@ if (args.named["--tls"]) {
|
||||
smtp.createServer(serverOpts, function(req) {
|
||||
// accept all incoming messages
|
||||
req.on("to", function(to, ack) {
|
||||
console.log(to);
|
||||
ack.accept();
|
||||
});
|
||||
|
||||
// send message to web endpoint
|
||||
req.on("message", function(stream, ack) {
|
||||
stream.pipe(process.stdout);
|
||||
stream.pipe(new MailParser().on("end", function(email) {
|
||||
http.post({
|
||||
url: serverOpts.endpoint,
|
||||
json: email
|
||||
}, function(err, res, body) {
|
||||
if (err) console.error(err);
|
||||
})
|
||||
}).on("error", function(err) {
|
||||
console.error(err);
|
||||
}));
|
||||
|
||||
ack.accept();
|
||||
});
|
||||
}).listen(process.env.NODE_PORT || 25);
|
||||
|
||||
|
||||
@ -2,14 +2,14 @@
|
||||
"name": "smtp2http",
|
||||
"version": "0.0.1",
|
||||
"description": "SMTP to HTTP gateway",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"smtp2http": "./bin/smtp2http.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"smtp-protocol": "^2",
|
||||
"squabble": "^1",
|
||||
"request": "^2"
|
||||
"request": "^2",
|
||||
"mailparser": "^0.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user