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"),
|
smtp = require("smtp-protocol"),
|
||||||
http = require("request"),
|
http = require("request"),
|
||||||
readFile = require("fs").readFileSync,
|
readFile = require("fs").readFileSync,
|
||||||
|
MailParser = require("mailparser").MailParser,
|
||||||
args,
|
args,
|
||||||
tlsTokens,
|
tlsTokens,
|
||||||
serverOpts = {};
|
serverOpts = {};
|
||||||
@ -13,6 +14,7 @@ squabble.shortOpts().longOpts().stopper()
|
|||||||
|
|
||||||
// parse arguments
|
// parse arguments
|
||||||
args = squabble.parse();
|
args = squabble.parse();
|
||||||
|
serverOpts.endpoint = args.named.ENDPOINT;
|
||||||
if (args.named["--tls"]) {
|
if (args.named["--tls"]) {
|
||||||
tlsTokens = args.named["--tls"].split(":");
|
tlsTokens = args.named["--tls"].split(":");
|
||||||
switch (tlsTokens.length) {
|
switch (tlsTokens.length) {
|
||||||
@ -37,12 +39,24 @@ if (args.named["--tls"]) {
|
|||||||
smtp.createServer(serverOpts, function(req) {
|
smtp.createServer(serverOpts, function(req) {
|
||||||
// accept all incoming messages
|
// accept all incoming messages
|
||||||
req.on("to", function(to, ack) {
|
req.on("to", function(to, ack) {
|
||||||
|
console.log(to);
|
||||||
ack.accept();
|
ack.accept();
|
||||||
});
|
});
|
||||||
|
|
||||||
// send message to web endpoint
|
// send message to web endpoint
|
||||||
req.on("message", function(stream, ack) {
|
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();
|
ack.accept();
|
||||||
});
|
});
|
||||||
}).listen(process.env.NODE_PORT || 25);
|
}).listen(process.env.NODE_PORT || 25);
|
||||||
|
|
||||||
|
|||||||
@ -2,14 +2,14 @@
|
|||||||
"name": "smtp2http",
|
"name": "smtp2http",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "SMTP to HTTP gateway",
|
"description": "SMTP to HTTP gateway",
|
||||||
"main": "index.js",
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"smtp2http": "./bin/smtp2http.js"
|
"smtp2http": "./bin/smtp2http.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"smtp-protocol": "^2",
|
"smtp-protocol": "^2",
|
||||||
"squabble": "^1",
|
"squabble": "^1",
|
||||||
"request": "^2"
|
"request": "^2",
|
||||||
|
"mailparser": "^0.5"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user