test-smtp-server 0.9.3 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@ Test SMTP Server is a lightweight wrapper for
|
|
|
4
4
|
[smtp-server](<https://nodemailer.com/extras/smtp-server/>).
|
|
5
5
|
It is primarily intended for development and testing. The test code can start the server, run email tests and then validate the email contents. It can replace the use of external fake SMTP services which may have availablility issues.
|
|
6
6
|
|
|
7
|
-
All received emails are stored in an array. The emails
|
|
7
|
+
All received emails are stored in an array in the order received. The emails
|
|
8
|
+
may be viewed as raw data or a parsed object that is easily examined.
|
|
8
9
|
|
|
9
10
|
## Getting Started
|
|
10
11
|
|
|
@@ -31,8 +32,9 @@ import { testSmtpServer } from "test-smtp-server";
|
|
|
31
32
|
await smtpserver.startServer(); // start listening
|
|
32
33
|
|
|
33
34
|
// send some emails capturing ids ..
|
|
34
|
-
messageId.
|
|
35
|
+
messageId.push( await sendMail(email, smtpOptions));
|
|
35
36
|
|
|
37
|
+
// get emails in sent order
|
|
36
38
|
const mails = smtpserver.getEmails();
|
|
37
39
|
|
|
38
40
|
// validate/dump emails
|
|
@@ -23,9 +23,11 @@ export declare class eMail {
|
|
|
23
23
|
/**
|
|
24
24
|
* testSmtpServer optional parameters
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export type testSmtpServerOptions = {
|
|
27
27
|
/** the port number to use (default: 1025) */
|
|
28
28
|
smtpPort?: number;
|
|
29
|
+
/** restrict ip addresses to localhost */
|
|
30
|
+
localhostOnly?: boolean;
|
|
29
31
|
/** logging function like console.log() */
|
|
30
32
|
debug?: (message?: unknown, ...optionalParams: any[]) => void;
|
|
31
33
|
};
|
|
@@ -38,6 +40,7 @@ export declare class testSmtpServer {
|
|
|
38
40
|
private debug;
|
|
39
41
|
private emails;
|
|
40
42
|
private isDebugging;
|
|
43
|
+
private localhostOnly;
|
|
41
44
|
private port;
|
|
42
45
|
private server;
|
|
43
46
|
constructor(options?: testSmtpServerOptions | undefined);
|
|
@@ -48,7 +51,7 @@ export declare class testSmtpServer {
|
|
|
48
51
|
*/
|
|
49
52
|
clearEmails(): number;
|
|
50
53
|
/**
|
|
51
|
-
* Retrieve the set of emails in order from
|
|
54
|
+
* Retrieve the set of emails in order from oldest to most recent.
|
|
52
55
|
*
|
|
53
56
|
* @returns array of eMail objects
|
|
54
57
|
*/
|
|
@@ -50,11 +50,15 @@ class testSmtpServer {
|
|
|
50
50
|
this.debug = (_message, ..._optionalParams) => { };
|
|
51
51
|
this.emails = [];
|
|
52
52
|
this.isDebugging = false;
|
|
53
|
+
this.localhostOnly = true;
|
|
53
54
|
this.port = 1025;
|
|
54
55
|
if (options) {
|
|
55
56
|
if (options.smtpPort) {
|
|
56
57
|
this.port = options.smtpPort;
|
|
57
58
|
}
|
|
59
|
+
if (options.localhostOnly) {
|
|
60
|
+
this.localhostOnly = options.localhostOnly;
|
|
61
|
+
}
|
|
58
62
|
if (options.debug) {
|
|
59
63
|
this.debug = options.debug;
|
|
60
64
|
}
|
|
@@ -64,7 +68,8 @@ class testSmtpServer {
|
|
|
64
68
|
this.server = new smtp_server_1.SMTPServer({
|
|
65
69
|
authOptional: true,
|
|
66
70
|
onConnect(session, callback) {
|
|
67
|
-
|
|
71
|
+
// 172.17 prefix is a linux docker container
|
|
72
|
+
if (that.localhostOnly && !session.remoteAddress.match(/^172.17|127.0.0.1|::1$/)) {
|
|
68
73
|
return callback(new Error("Only connections from localhost allowed"));
|
|
69
74
|
}
|
|
70
75
|
return callback(); // Accept the connection
|
|
@@ -85,7 +90,7 @@ class testSmtpServer {
|
|
|
85
90
|
stream.on("end", () => {
|
|
86
91
|
const buffer = Buffer.concat(buffers);
|
|
87
92
|
const email = new eMail(session.envelope, buffer);
|
|
88
|
-
that.emails.
|
|
93
|
+
that.emails.push(email);
|
|
89
94
|
if (that.isDebugging) {
|
|
90
95
|
that.debug(JSON.stringify(email, (key, value) => {
|
|
91
96
|
if ("buffer" === key) {
|
|
@@ -113,7 +118,7 @@ class testSmtpServer {
|
|
|
113
118
|
return count;
|
|
114
119
|
}
|
|
115
120
|
/**
|
|
116
|
-
* Retrieve the set of emails in order from
|
|
121
|
+
* Retrieve the set of emails in order from oldest to most recent.
|
|
117
122
|
*
|
|
118
123
|
* @returns array of eMail objects
|
|
119
124
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "test-smtp-server",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "The test-smtp-server package allows internal testing of projects needing an SMTP server.",
|
|
5
5
|
"main": "./build/lib/test-smtp-server.js",
|
|
6
6
|
"types": "./build/lib/test-smtp-server.d.ts",
|
|
@@ -44,20 +44,20 @@
|
|
|
44
44
|
"url": "git+https://github.com/webstech/test-smtp-server"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/nodemailer": "^6.4.
|
|
47
|
+
"@types/nodemailer": "^6.4.7",
|
|
48
48
|
"@types/smtp-server": "^3.5.7",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
50
|
-
"@typescript-eslint/parser": "^5.
|
|
51
|
-
"commander": "^9.
|
|
52
|
-
"eslint": "^8.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.47.0",
|
|
51
|
+
"commander": "^9.4.1",
|
|
52
|
+
"eslint": "^8.30.0",
|
|
53
53
|
"eslint-config-prettier": "^8.5.0",
|
|
54
|
-
"eslint-plugin-jsdoc": "^39.
|
|
54
|
+
"eslint-plugin-jsdoc": "^39.6.4",
|
|
55
55
|
"nodemailer": "^6.7.5",
|
|
56
|
-
"typescript": "^4.
|
|
56
|
+
"typescript": "^4.9.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@types/mailparser": "^3.4.0",
|
|
60
|
-
"mailparser": "^3.
|
|
60
|
+
"mailparser": "^3.6.2",
|
|
61
61
|
"smtp-server": "^3.11.0"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|