forked from fleebzz/carbone-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsmtp-dummy.js
49 lines (41 loc) · 1.41 KB
/
smtp-dummy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { SMTPServer } = require("smtp-server");
const { simpleParser } = require("mailparser");
const server = new SMTPServer({
// disable encryption and auth for very easy access
secure: false,
authOptional: true,
// important: call callback!
onConnect: (session, callback) => {
console.log("connection established");
callback();
},
// no callback here, close event is purely informational
onClose: () => console.log("connection closed"),
// important: consume the stream with listeners on 'data' and
// call callback
onData: (stream, session, callback) => {
simpleParser(stream, (err, parsed) => {
const { from, to, attachments, subject, text } = parsed;
if (err) {
return callback(err);
}
console.log("GOT MAIL");
console.log(` from: ${from.text}`);
console.log(` to: ${to.value.map(addr => addr.address).join(", ")}`);
console.log(` subject: ${subject}`);
console.log(` text: ${text}`);
if (attachments.length > 0) {
console.log(" attachments:");
for (const attachment of attachments) {
console.log(` ${attachment.filename} (${attachment.size}B)`);
}
} else {
console.log(" no attachments D:");
}
callback();
});
}
});
const port = 3535;
// inform the user about the port that's used
server.listen(port, () => console.log(`listening on localhost:${port}`));