emailjs 3.7.0 → 4.0.0

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.
@@ -1853,8 +1853,9 @@ class SMTPClient {
1853
1853
  }
1854
1854
  /**
1855
1855
  * @public
1856
- * @param {Message} msg the message to send
1857
- * @param {function(err: Error, msg: Message): void} callback .
1856
+ * @template {Message | MessageHeaders} T
1857
+ * @param {T} msg the message to send
1858
+ * @param {MessageCallback<T>} callback receiver for the error (if any) as well as the passed-in message / headers
1858
1859
  * @returns {void}
1859
1860
  */
1860
1861
  send(msg, callback) {
@@ -1882,17 +1883,20 @@ class SMTPClient {
1882
1883
  }
1883
1884
  /**
1884
1885
  * @public
1885
- * @param {Message} msg the message to send
1886
- * @returns {Promise<Message>} a promise that resolves to the fully processed message
1886
+ * @template {Message | MessageHeaders} T
1887
+ * @param {T} msg the message to send
1888
+ * @returns {Promise<T>} a promise that resolves to the passed-in message / headers
1887
1889
  */
1888
1890
  sendAsync(msg) {
1889
1891
  return new Promise((resolve, reject) => {
1890
- this.send(msg, (err, msg) => {
1892
+ this.send(msg, (err, message) => {
1891
1893
  if (err != null) {
1892
1894
  reject(err);
1893
1895
  }
1894
1896
  else {
1895
- resolve(msg);
1897
+ // unfortunately, the conditional type doesn't reach here
1898
+ // fortunately, we only return a `Message` when err is null, so this is safe
1899
+ resolve(message);
1896
1900
  }
1897
1901
  });
1898
1902
  });
@@ -1901,7 +1905,7 @@ class SMTPClient {
1901
1905
  * @public
1902
1906
  * @description Converts a message to the raw object used by the internal stack.
1903
1907
  * @param {Message} message message to convert
1904
- * @param {function(err: Error, msg: Message): void} callback errback
1908
+ * @param {MessageCallback} callback errback
1905
1909
  * @returns {MessageStack} raw message object
1906
1910
  */
1907
1911
  createMessageStack(message, callback = function () {
@@ -2118,4 +2122,4 @@ class SMTPClient {
2118
2122
  }
2119
2123
 
2120
2124
  export { AUTH_METHODS, BUFFERSIZE, DEFAULT_TIMEOUT, MIME64CHUNK, MIMECHUNK, Message, SMTPClient, SMTPConnection, SMTPError, SMTPErrorStates, SMTPResponseMonitor, SMTPState, addressparser, getRFC2822Date, getRFC2822DateUTC, isRFC2822Date, mimeEncode, mimeWordEncode };
2121
- //# sourceMappingURL=email.mjs.map
2125
+ //# sourceMappingURL=email.js.map
package/email.ts CHANGED
@@ -1,8 +1,8 @@
1
- export * from './smtp/address';
2
- export * from './smtp/client';
3
- export * from './smtp/connection';
4
- export * from './smtp/date';
5
- export * from './smtp/error';
6
- export * from './smtp/message';
7
- export * from './smtp/mime';
8
- export * from './smtp/response';
1
+ export * from './smtp/address.js';
2
+ export * from './smtp/client.js';
3
+ export * from './smtp/connection.js';
4
+ export * from './smtp/date.js';
5
+ export * from './smtp/error.js';
6
+ export * from './smtp/message.js';
7
+ export * from './smtp/mime.js';
8
+ export * from './smtp/response.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "emailjs",
3
3
  "description": "send text/html emails and attachments (files, streams and strings) from node.js to any smtp server",
4
- "version": "3.7.0",
4
+ "version": "4.0.0",
5
5
  "author": "eleith",
6
6
  "contributors": [
7
7
  "izuzak",
@@ -17,48 +17,52 @@
17
17
  "type": "module",
18
18
  "devDependencies": {
19
19
  "@ledge/configs": "23.3.23322",
20
- "@rollup/plugin-typescript": "8.3.0",
20
+ "@rollup/plugin-typescript": "8.3.2",
21
21
  "@types/mailparser": "3.4.0",
22
- "@types/node": "16.11.9",
22
+ "@types/node": "12.12.6",
23
23
  "@types/smtp-server": "3.5.7",
24
- "@typescript-eslint/eslint-plugin": "5.4.0",
25
- "@typescript-eslint/parser": "5.4.0",
26
- "ava": "3.15.0",
27
- "eslint": "7.32.0",
28
- "eslint-config-prettier": "8.3.0",
24
+ "@typescript-eslint/eslint-plugin": "5.19.0",
25
+ "@typescript-eslint/parser": "5.19.0",
26
+ "ava": "4.2.0",
27
+ "eslint": "8.13.0",
28
+ "eslint-config-prettier": "8.5.0",
29
29
  "eslint-plugin-prettier": "4.0.0",
30
30
  "mailparser": "3.4.0",
31
- "prettier": "2.4.1",
32
- "rollup": "2.60.0",
33
- "smtp-server": "3.9.0",
34
- "ts-node": "10.4.0",
31
+ "prettier": "2.6.2",
32
+ "rollup": "2.70.1",
33
+ "smtp-server": "3.10.0",
34
+ "ts-node": "10.7.0",
35
35
  "tslib": "2.3.1",
36
- "typescript": "4.5.2"
36
+ "typescript": "4.3.5"
37
+ },
38
+ "peerDependencies": {
39
+ "typescript": ">=4.3.5"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "typescript": {
43
+ "optional": true
44
+ }
37
45
  },
38
46
  "resolutions": {
39
- "nodemailer": "6.7.1"
47
+ "nodemailer": "6.7.3"
40
48
  },
41
49
  "engines": {
42
- "node": ">=10"
50
+ "node": ">=12"
43
51
  },
44
52
  "files": [
53
+ "email.js",
45
54
  "email.ts",
46
- "smtp",
47
- "rollup"
55
+ "smtp"
48
56
  ],
49
- "main": "./rollup/email.cjs",
50
57
  "types": "./email.ts",
51
58
  "exports": {
52
- "import": "./rollup/email.mjs",
53
- "require": "./rollup/email.cjs"
59
+ "default": "./email.js"
54
60
  },
55
61
  "scripts": {
56
62
  "build": "rollup -c rollup.config.ts",
57
63
  "lint": "eslint *.ts \"+(smtp|test)/*.ts\"",
58
- "tsc": "tsc",
59
- "test": "ava",
60
- "pretest-cjs": "npm run build",
61
- "test-cjs": "npm run test -- --node-arguments='--title=cjs'"
64
+ "pretest": "yarn build",
65
+ "test": "ava"
62
66
  },
63
67
  "license": "MIT"
64
68
  }
package/smtp/client.ts CHANGED
@@ -1,9 +1,19 @@
1
- import { addressparser } from './address';
2
- import { Message, MessageAttachment, MessageHeaders } from './message';
3
- import { SMTPConnection, SMTPConnectionOptions, SMTPState } from './connection';
1
+ import { addressparser } from './address.js';
2
+ import type { MessageAttachment, MessageHeaders } from './message.js';
3
+ import { Message } from './message.js';
4
+ import type { SMTPConnectionOptions } from './connection.js';
5
+ import { SMTPConnection, SMTPState } from './connection.js';
6
+
7
+ export type MessageCallback<T = Message | MessageHeaders> = <
8
+ U extends Error | null,
9
+ V extends U extends Error ? T : Message
10
+ >(
11
+ err: U,
12
+ msg: V
13
+ ) => void;
4
14
 
5
15
  export interface MessageStack {
6
- callback: (error: Error | null, message: Message) => void;
16
+ callback: MessageCallback;
7
17
  message: Message;
8
18
  attachment: MessageAttachment;
9
19
  text: string;
@@ -35,15 +45,16 @@ export class SMTPClient {
35
45
 
36
46
  /**
37
47
  * @public
38
- * @param {Message} msg the message to send
39
- * @param {function(err: Error, msg: Message): void} callback .
48
+ * @template {Message | MessageHeaders} T
49
+ * @param {T} msg the message to send
50
+ * @param {MessageCallback<T>} callback receiver for the error (if any) as well as the passed-in message / headers
40
51
  * @returns {void}
41
52
  */
42
- public send(
43
- msg: Message,
44
- callback: (err: Error | null, msg: Message) => void
45
- ) {
46
- const message: Message | null =
53
+ public send<T extends Message | MessageHeaders>(
54
+ msg: T,
55
+ callback: MessageCallback<T>
56
+ ): void {
57
+ const message =
47
58
  msg instanceof Message
48
59
  ? msg
49
60
  : this._canMakeMessage(msg)
@@ -71,16 +82,19 @@ export class SMTPClient {
71
82
 
72
83
  /**
73
84
  * @public
74
- * @param {Message} msg the message to send
75
- * @returns {Promise<Message>} a promise that resolves to the fully processed message
85
+ * @template {Message | MessageHeaders} T
86
+ * @param {T} msg the message to send
87
+ * @returns {Promise<T>} a promise that resolves to the passed-in message / headers
76
88
  */
77
- public sendAsync(msg: Message) {
89
+ public sendAsync<T extends Message | MessageHeaders>(msg: T) {
78
90
  return new Promise<Message>((resolve, reject) => {
79
- this.send(msg, (err, msg) => {
91
+ this.send(msg, (err, message) => {
80
92
  if (err != null) {
81
93
  reject(err);
82
94
  } else {
83
- resolve(msg);
95
+ // unfortunately, the conditional type doesn't reach here
96
+ // fortunately, we only return a `Message` when err is null, so this is safe
97
+ resolve(message as Message);
84
98
  }
85
99
  });
86
100
  });
@@ -90,12 +104,12 @@ export class SMTPClient {
90
104
  * @public
91
105
  * @description Converts a message to the raw object used by the internal stack.
92
106
  * @param {Message} message message to convert
93
- * @param {function(err: Error, msg: Message): void} callback errback
107
+ * @param {MessageCallback} callback errback
94
108
  * @returns {MessageStack} raw message object
95
109
  */
96
110
  public createMessageStack(
97
111
  message: Message,
98
- callback: (err: Error | null, msg: Message) => void = function () {
112
+ callback: MessageCallback = function () {
99
113
  /* ø */
100
114
  }
101
115
  ) {
@@ -231,7 +245,7 @@ export class SMTPClient {
231
245
  * @returns {boolean} whether the attachment contains inlined html
232
246
  */
233
247
  protected _containsInlinedHtml(
234
- attachment: MessageAttachment | MessageAttachment[]
248
+ attachment?: MessageAttachment | MessageAttachment[]
235
249
  ) {
236
250
  if (Array.isArray(attachment)) {
237
251
  return attachment.some((att) => {
@@ -247,7 +261,7 @@ export class SMTPClient {
247
261
  * @param {MessageAttachment} attachment attachment
248
262
  * @returns {boolean} whether the attachment is inlined html
249
263
  */
250
- protected _isAttachmentInlinedHtml(attachment: MessageAttachment) {
264
+ protected _isAttachmentInlinedHtml(attachment?: MessageAttachment) {
251
265
  return (
252
266
  attachment &&
253
267
  (attachment.data || attachment.path) &&
@@ -2,15 +2,11 @@ import { createHmac } from 'crypto';
2
2
  import { EventEmitter } from 'events';
3
3
  import { Socket } from 'net';
4
4
  import { hostname } from 'os';
5
- import {
6
- connect,
7
- createSecureContext,
8
- ConnectionOptions,
9
- TLSSocket,
10
- } from 'tls';
5
+ import { connect, createSecureContext, TLSSocket } from 'tls';
6
+ import type { ConnectionOptions } from 'tls';
11
7
 
12
- import { SMTPError, SMTPErrorStates } from './error';
13
- import { SMTPResponseMonitor } from './response';
8
+ import { SMTPError, SMTPErrorStates } from './error.js';
9
+ import { SMTPResponseMonitor } from './response.js';
14
10
 
15
11
  /**
16
12
  * @readonly
package/smtp/message.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import type { PathLike } from 'fs';
1
2
  import {
2
- PathLike,
3
3
  existsSync,
4
4
  open as openFile,
5
5
  close as closeFile,
@@ -10,9 +10,9 @@ import { hostname } from 'os';
10
10
  import { Stream } from 'stream';
11
11
  import type { Readable } from 'stream';
12
12
 
13
- import { addressparser } from './address';
14
- import { getRFC2822Date } from './date';
15
- import { mimeWordEncode } from './mime';
13
+ import { addressparser } from './address.js';
14
+ import { getRFC2822Date } from './date.js';
15
+ import { mimeWordEncode } from './mime.js';
16
16
 
17
17
  const CRLF = '\r\n' as const;
18
18
 
@@ -68,19 +68,20 @@ export interface MessageHeaders {
68
68
  | string
69
69
  | string[]
70
70
  | null
71
+ | undefined
71
72
  | MessageAttachment
72
73
  | MessageAttachment[];
73
- 'content-type': string;
74
- 'message-id': string;
75
- 'return-path': string | null;
76
- date: string;
74
+ 'content-type'?: string;
75
+ 'message-id'?: string;
76
+ 'return-path'?: string | null;
77
+ date?: string;
77
78
  from: string | string[];
78
79
  to: string | string[];
79
- cc: string | string[];
80
- bcc: string | string[];
80
+ cc?: string | string[];
81
+ bcc?: string | string[];
81
82
  subject: string;
82
83
  text: string | null;
83
- attachment: MessageAttachment | MessageAttachment[];
84
+ attachment?: MessageAttachment | MessageAttachment[];
84
85
  }
85
86
 
86
87
  let counter = 0;
package/smtp/response.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SMTPError, SMTPErrorStates } from './error';
1
+ import { SMTPError, SMTPErrorStates } from './error.js';
2
2
  import type { Socket } from 'net';
3
3
  import type { TLSSocket } from 'tls';
4
4
 
package/CHANGELOG.md DELETED
@@ -1,114 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
- and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
-
7
- ## [3.6.1] - TBD
8
- ### Fixed
9
- - remove call to deprecated `RegExp.prototype.compile` (causes build error on typescript@4.5)
10
-
11
- ## [3.6.0] - 2021-09-03
12
- ### Added
13
- - support `tsc` compilation without `--esModuleInterop` or `--allowSyntheticDefaultImports` [#296](https://github.com/eleith/emailjs/pull/296)
14
- - `Message#readAsync` API [#297](https://github.com/eleith/emailjs/pull/297)
15
- - `Message#checkValidity` API [#298](https://github.com/eleith/emailjs/pull/298)
16
-
17
- ### Deprecated
18
- - `Message#valid` API [#298](https://github.com/eleith/emailjs/pull/298)
19
-
20
- ## [3.5.0] - 2021-06-28
21
- ### Added
22
- - support `tsc --noPropertyAccessFromIndexSignature` [#290](https://github.com/eleith/emailjs/pull/290)
23
-
24
- ### Fixed
25
- - use `engines` field in `package.json` to signal node version support
26
-
27
- ## [3.4.0] - 2020-12-01
28
- ### Added
29
- - `SMTPClient#sendAsync` API [#267](https://github.com/eleith/emailjs/issues/267)
30
- - `isRFC2822Date` API
31
-
32
- ### Changed
33
- - use `WeakSet` instead of `WeakMap` for greylist tracking
34
-
35
- ### Fixed
36
- - use camelCase style for internal function names
37
- - use correct types in jsdoc comments
38
-
39
- ## [3.3.0] - 2020-08-08
40
- ### Added
41
- - greylist support [#202](https://github.com/eleith/emailjs/issues/202)
42
-
43
- ### Fixed
44
- - check socket is writable before sending [#205](https://github.com/eleith/emailjs/issues/205)
45
-
46
- ## [3.2.1] - 2020-06-27
47
- ### Fixed
48
- - use correct type for `MessageAttachment.stream` [#261](https://github.com/eleith/emailjs/issues/261)
49
- - add missing types in mime functions [#262](https://github.com/eleith/emailjs/pull/262)
50
-
51
- ## [3.2.0] - 2020-06-19
52
- ### Added
53
- - `addressparser` API (forked from dropped dependency) [#259](https://github.com/eleith/emailjs/issues/259)
54
- - `mimeEncode`/`mimeWordEncode` APIs (forked from dropped dependency) [#247](https://github.com/eleith/emailjs/issues/247)
55
-
56
- ### Changed
57
- - drop dependency on `addressparser` [#259](https://github.com/eleith/emailjs/issues/259)
58
- - drop dependency on `emailjs-mime-codec` [#247](https://github.com/eleith/emailjs/issues/247)
59
-
60
- ### Fixed
61
- - make `MessageAttachment` interface usable [#254](https://github.com/eleith/emailjs/issues/254)
62
- - mend regression in address type validation [#252](https://github.com/eleith/emailjs/pull/252)
63
-
64
- ## [3.1.0] - 2020-06-19 [YANKED]
65
-
66
- ## [3.0.0] - 2020-05-28
67
- ### Added
68
- - convert source to strict typescript, listed under the `types` field in `package.json`
69
- - support "dual-package" ESM + CJS via [conditional exports](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_conditional_exports) & `rollup`-generated bundles
70
- - `SMTPClient#creatMessageStack` API [#229](https://github.com/eleith/emailjs/issues/229)
71
- - `SMTPError` API
72
-
73
- ### Changed
74
- - simplify public API [#249](https://github.com/eleith/emailjs/issues/249)
75
- - rename `Client` -> `SMTPClient` [#249](https://github.com/eleith/emailjs/issues/249)
76
- - rename `SMTPResponse` -> `SMTPResponseMonitor` [#249](https://github.com/eleith/emailjs/issues/249)
77
-
78
- ### Removed
79
- - `Message#attach_alternative` API
80
- - `makeSMTPError` API
81
-
82
- ### Fixed
83
- - filter duplicate message recipients [#242](https://github.com/eleith/emailjs/issues/242)
84
- - error when passing `password` without `user` [#199](https://github.com/eleith/emailjs/issues/199)
85
- - trim `host` before connecting [#136](https://github.com/eleith/emailjs/issues/136)
86
-
87
- ## [2.2.0] - 2018-07-06
88
- ### Added
89
- - expose rfc2822 date module
90
- - annotate code with typescript-compatible jsdoc tags
91
-
92
- ### Changed
93
- - drop dependency on `moment`
94
- - drop dependency on `starttls`
95
-
96
- ### Fixed
97
- - ensure timeout is set to default value [#225](https://github.com/eleith/emailjs/issues/225)
98
-
99
- ## [2.1.0] - 2018-06-09
100
- ### Added
101
- - expose error module
102
-
103
- ### Changed
104
- - handle errors with `fs.closeSync` instead of `fs.close`
105
- - refactor to ES2015+ constructs
106
- - lint & format with eslint + prettier
107
- - drop optional dependency on `bufferjs`
108
-
109
- ### Fixed
110
- - remove `new Buffer` calls
111
-
112
- ## [2.0.1] - 2018-02-11
113
- ### Added
114
- - a new changelog