@remit/smtp-service 0.0.2 → 0.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/smtp-service",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "git+https://github.com/remit-mail/remit.git",
27
+ "url": "git+https://github.com/remit-mail/reader.git",
28
28
  "directory": "packages/smtp-service"
29
29
  }
30
30
  }
@@ -51,194 +51,190 @@ const createTestMessage = (
51
51
  };
52
52
  };
53
53
 
54
- describe(
55
- "SMTP client integration tests",
56
- {
57
- skip: !process.env.RUN_INTEG_TESTS,
58
- },
59
- () => {
60
- describe("sendMail", () => {
61
- test("sends a simple text message", async () => {
62
- const message = createTestMessage({
63
- subject: `Simple text test ${Date.now()}`,
64
- text: "Hello from the SMTP integration test!",
65
- });
66
-
67
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
68
-
69
- assert.equal(result.success, true, "Send should succeed");
70
- assert.equal(result.isTransient, false, "Should not be transient");
71
- assert.ok(result.messageId, "Should return a message ID");
72
- assert.ok(result.response, "Should return an SMTP response");
54
+ describe("SMTP client integration tests", {
55
+ skip: !process.env.RUN_INTEG_TESTS,
56
+ }, () => {
57
+ describe("sendMail", () => {
58
+ test("sends a simple text message", async () => {
59
+ const message = createTestMessage({
60
+ subject: `Simple text test ${Date.now()}`,
61
+ text: "Hello from the SMTP integration test!",
73
62
  });
74
63
 
75
- test("sends an HTML message", async () => {
76
- const message = createTestMessage({
77
- subject: `HTML test ${Date.now()}`,
78
- text: "Plain text fallback",
79
- html: "<html><body><h1>Hello!</h1><p>This is an <strong>HTML</strong> message.</p></body></html>",
80
- });
64
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
81
65
 
82
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
66
+ assert.equal(result.success, true, "Send should succeed");
67
+ assert.equal(result.isTransient, false, "Should not be transient");
68
+ assert.ok(result.messageId, "Should return a message ID");
69
+ assert.ok(result.response, "Should return an SMTP response");
70
+ });
83
71
 
84
- assert.equal(result.success, true, "Send should succeed");
85
- assert.ok(result.messageId, "Should return a message ID");
72
+ test("sends an HTML message", async () => {
73
+ const message = createTestMessage({
74
+ subject: `HTML test ${Date.now()}`,
75
+ text: "Plain text fallback",
76
+ html: "<html><body><h1>Hello!</h1><p>This is an <strong>HTML</strong> message.</p></body></html>",
86
77
  });
87
78
 
88
- test("sends a message with CC recipients", async () => {
89
- const message = createTestMessage({
90
- subject: `CC test ${Date.now()}`,
91
- to: ["bob@mokapi.io"],
92
- cc: ["alice@mokapi.io"],
93
- text: "Message with CC recipient",
94
- });
79
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
95
80
 
96
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
81
+ assert.equal(result.success, true, "Send should succeed");
82
+ assert.ok(result.messageId, "Should return a message ID");
83
+ });
97
84
 
98
- assert.equal(result.success, true, "Send should succeed");
99
- assert.ok(result.messageId, "Should return a message ID");
85
+ test("sends a message with CC recipients", async () => {
86
+ const message = createTestMessage({
87
+ subject: `CC test ${Date.now()}`,
88
+ to: ["bob@mokapi.io"],
89
+ cc: ["alice@mokapi.io"],
90
+ text: "Message with CC recipient",
100
91
  });
101
92
 
102
- test("sends a message with BCC recipients", async () => {
103
- const message = createTestMessage({
104
- subject: `BCC test ${Date.now()}`,
105
- to: ["bob@mokapi.io"],
106
- bcc: ["alice@mokapi.io"],
107
- text: "Message with BCC recipient",
108
- });
93
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
109
94
 
110
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
95
+ assert.equal(result.success, true, "Send should succeed");
96
+ assert.ok(result.messageId, "Should return a message ID");
97
+ });
111
98
 
112
- assert.equal(result.success, true, "Send should succeed");
113
- assert.ok(result.messageId, "Should return a message ID");
99
+ test("sends a message with BCC recipients", async () => {
100
+ const message = createTestMessage({
101
+ subject: `BCC test ${Date.now()}`,
102
+ to: ["bob@mokapi.io"],
103
+ bcc: ["alice@mokapi.io"],
104
+ text: "Message with BCC recipient",
114
105
  });
115
106
 
116
- test("sends a message with multiple recipients", async () => {
117
- const message = createTestMessage({
118
- subject: `Multiple recipients test ${Date.now()}`,
119
- to: ["bob@mokapi.io", "alice@mokapi.io"],
120
- text: "Message to multiple recipients",
121
- });
107
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
122
108
 
123
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
109
+ assert.equal(result.success, true, "Send should succeed");
110
+ assert.ok(result.messageId, "Should return a message ID");
111
+ });
124
112
 
125
- assert.equal(result.success, true, "Send should succeed");
126
- assert.ok(result.messageId, "Should return a message ID");
113
+ test("sends a message with multiple recipients", async () => {
114
+ const message = createTestMessage({
115
+ subject: `Multiple recipients test ${Date.now()}`,
116
+ to: ["bob@mokapi.io", "alice@mokapi.io"],
117
+ text: "Message to multiple recipients",
127
118
  });
128
119
 
129
- test("sends a reply with In-Reply-To header", async () => {
130
- const originalMessageId = "<original-message-123@mokapi.io>";
131
- const message = createTestMessage({
132
- subject: `Re: Original subject ${Date.now()}`,
133
- text: "This is a reply to your message.",
134
- inReplyTo: originalMessageId,
135
- });
120
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
136
121
 
137
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
122
+ assert.equal(result.success, true, "Send should succeed");
123
+ assert.ok(result.messageId, "Should return a message ID");
124
+ });
138
125
 
139
- assert.equal(result.success, true, "Send should succeed");
140
- assert.ok(result.messageId, "Should return a message ID");
126
+ test("sends a reply with In-Reply-To header", async () => {
127
+ const originalMessageId = "<original-message-123@mokapi.io>";
128
+ const message = createTestMessage({
129
+ subject: `Re: Original subject ${Date.now()}`,
130
+ text: "This is a reply to your message.",
131
+ inReplyTo: originalMessageId,
141
132
  });
142
133
 
143
- test("sends a reply with References header", async () => {
144
- const references = [
145
- "<msg-1@mokapi.io>",
146
- "<msg-2@mokapi.io>",
147
- "<msg-3@mokapi.io>",
148
- ].join(" ");
149
-
150
- const message = createTestMessage({
151
- subject: `Re: Thread subject ${Date.now()}`,
152
- text: "This is a reply in a thread.",
153
- inReplyTo: "<msg-3@mokapi.io>",
154
- references,
155
- });
134
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
156
135
 
157
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
136
+ assert.equal(result.success, true, "Send should succeed");
137
+ assert.ok(result.messageId, "Should return a message ID");
138
+ });
158
139
 
159
- assert.equal(result.success, true, "Send should succeed");
160
- assert.ok(result.messageId, "Should return a message ID");
140
+ test("sends a reply with References header", async () => {
141
+ const references = [
142
+ "<msg-1@mokapi.io>",
143
+ "<msg-2@mokapi.io>",
144
+ "<msg-3@mokapi.io>",
145
+ ].join(" ");
146
+
147
+ const message = createTestMessage({
148
+ subject: `Re: Thread subject ${Date.now()}`,
149
+ text: "This is a reply in a thread.",
150
+ inReplyTo: "<msg-3@mokapi.io>",
151
+ references,
161
152
  });
162
153
 
163
- test("sends a message with Reply-To address", async () => {
164
- const message = createTestMessage({
165
- subject: `Reply-To test ${Date.now()}`,
166
- text: "Please reply to a different address.",
167
- replyTo: "noreply@mokapi.io",
168
- });
154
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
169
155
 
170
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
156
+ assert.equal(result.success, true, "Send should succeed");
157
+ assert.ok(result.messageId, "Should return a message ID");
158
+ });
171
159
 
172
- assert.equal(result.success, true, "Send should succeed");
173
- assert.ok(result.messageId, "Should return a message ID");
160
+ test("sends a message with Reply-To address", async () => {
161
+ const message = createTestMessage({
162
+ subject: `Reply-To test ${Date.now()}`,
163
+ text: "Please reply to a different address.",
164
+ replyTo: "noreply@mokapi.io",
174
165
  });
175
166
 
176
- test("sends a message with formatted From name", async () => {
177
- const message = createTestMessage({
178
- from: '"Alice Test" <alice@mokapi.io>',
179
- subject: `From name test ${Date.now()}`,
180
- text: "Message with formatted From name",
181
- });
167
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
182
168
 
183
- const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
169
+ assert.equal(result.success, true, "Send should succeed");
170
+ assert.ok(result.messageId, "Should return a message ID");
171
+ });
184
172
 
185
- assert.equal(result.success, true, "Send should succeed");
186
- assert.ok(result.messageId, "Should return a message ID");
173
+ test("sends a message with formatted From name", async () => {
174
+ const message = createTestMessage({
175
+ from: '"Alice Test" <alice@mokapi.io>',
176
+ subject: `From name test ${Date.now()}`,
177
+ text: "Message with formatted From name",
187
178
  });
188
179
 
189
- test("handles connection failure gracefully", async () => {
190
- const badConfig: SmtpConfig = {
191
- host: "localhost",
192
- port: 9999, // Non-existent port
193
- secure: false,
194
- user: "alice@mokapi.io",
195
- credentials: { kind: "password", password: "alice123" },
196
- connectionTimeout: 1000, // Short timeout for tests
197
- };
180
+ const result = await sendMail(MOKAPI_SMTP_CONFIG, message);
198
181
 
199
- const message = createTestMessage();
200
- const result = await sendMail(badConfig, message);
182
+ assert.equal(result.success, true, "Send should succeed");
183
+ assert.ok(result.messageId, "Should return a message ID");
184
+ });
201
185
 
202
- assert.equal(result.success, false, "Send should fail");
203
- assert.ok(result.error, "Should return an error");
204
- // Connection errors are typically transient
205
- assert.equal(
206
- result.isTransient,
207
- false,
208
- "Connection errors without SMTP code are not transient",
209
- );
210
- });
186
+ test("handles connection failure gracefully", async () => {
187
+ const badConfig: SmtpConfig = {
188
+ host: "localhost",
189
+ port: 9999, // Non-existent port
190
+ secure: false,
191
+ user: "alice@mokapi.io",
192
+ credentials: { kind: "password", password: "alice123" },
193
+ connectionTimeout: 1000, // Short timeout for tests
194
+ };
195
+
196
+ const message = createTestMessage();
197
+ const result = await sendMail(badConfig, message);
198
+
199
+ assert.equal(result.success, false, "Send should fail");
200
+ assert.ok(result.error, "Should return an error");
201
+ // Connection errors are typically transient
202
+ assert.equal(
203
+ result.isTransient,
204
+ false,
205
+ "Connection errors without SMTP code are not transient",
206
+ );
207
+ });
211
208
 
212
- test("handles authentication failure", async () => {
213
- const badAuthConfig: SmtpConfig = {
214
- host: "localhost",
215
- port: 2525,
216
- secure: false,
217
- user: "alice@mokapi.io",
218
- credentials: { kind: "password", password: "wrong-password" },
219
- tls: {
220
- rejectUnauthorized: false,
221
- },
222
- connectionTimeout: 5000,
223
- };
224
-
225
- const message = createTestMessage();
226
- const result = await sendMail(badAuthConfig, message);
227
-
228
- // mokapi may or may not enforce authentication
229
- // If it does, this should fail; if not, it will succeed
230
- if (!result.success) {
231
- assert.ok(result.error, "Should return an error");
232
- // 5xx errors are permanent (not transient)
233
- if (result.smtpCode && result.smtpCode >= 500) {
234
- assert.equal(
235
- result.isTransient,
236
- false,
237
- "Auth failure should be permanent",
238
- );
239
- }
209
+ test("handles authentication failure", async () => {
210
+ const badAuthConfig: SmtpConfig = {
211
+ host: "localhost",
212
+ port: 2525,
213
+ secure: false,
214
+ user: "alice@mokapi.io",
215
+ credentials: { kind: "password", password: "wrong-password" },
216
+ tls: {
217
+ rejectUnauthorized: false,
218
+ },
219
+ connectionTimeout: 5000,
220
+ };
221
+
222
+ const message = createTestMessage();
223
+ const result = await sendMail(badAuthConfig, message);
224
+
225
+ // mokapi may or may not enforce authentication
226
+ // If it does, this should fail; if not, it will succeed
227
+ if (!result.success) {
228
+ assert.ok(result.error, "Should return an error");
229
+ // 5xx errors are permanent (not transient)
230
+ if (result.smtpCode && result.smtpCode >= 500) {
231
+ assert.equal(
232
+ result.isTransient,
233
+ false,
234
+ "Auth failure should be permanent",
235
+ );
240
236
  }
241
- });
237
+ }
242
238
  });
243
- },
244
- );
239
+ });
240
+ });