nodemailer 10.4.1 → 10.5.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.
- package/CHANGELOG.md +13 -0
- package/README.md +21 -0
- package/dist/cjs/dkim/sign.js +2 -2
- package/dist/cjs/errors.d.ts +2 -0
- package/dist/cjs/errors.js +11 -1
- package/dist/cjs/json-transport/index.js +2 -0
- package/dist/cjs/mailer/index.d.ts +5 -0
- package/dist/cjs/mailer/index.js +56 -4
- package/dist/cjs/mailer/mail-message.d.ts +10 -0
- package/dist/cjs/mime-funcs/index.d.ts +2 -1
- package/dist/cjs/mime-funcs/index.js +72 -2
- package/dist/cjs/mime-node/index.js +1 -79
- package/dist/cjs/package-info.d.ts +1 -1
- package/dist/cjs/package-info.js +1 -1
- package/dist/cjs/shared/index.d.ts +23 -0
- package/dist/cjs/shared/index.js +79 -0
- package/dist/cjs/smtp-connection/index.js +6 -0
- package/dist/cjs/smtp-pool/index.d.ts +1 -0
- package/dist/cjs/smtp-pool/index.js +57 -6
- package/dist/cjs/smtp-pool/pool-resource.js +26 -4
- package/dist/cjs/smtp-transport/index.d.ts +1 -0
- package/dist/cjs/smtp-transport/index.js +47 -35
- package/dist/esm/dkim/sign.js +2 -2
- package/dist/esm/errors.d.ts +2 -0
- package/dist/esm/errors.js +9 -0
- package/dist/esm/json-transport/index.js +2 -0
- package/dist/esm/mailer/index.d.ts +5 -0
- package/dist/esm/mailer/index.js +56 -4
- package/dist/esm/mailer/mail-message.d.ts +10 -0
- package/dist/esm/mime-funcs/index.d.ts +2 -1
- package/dist/esm/mime-funcs/index.js +72 -2
- package/dist/esm/mime-node/index.js +1 -79
- package/dist/esm/package-info.d.ts +1 -1
- package/dist/esm/package-info.js +1 -1
- package/dist/esm/shared/index.d.ts +23 -0
- package/dist/esm/shared/index.js +78 -0
- package/dist/esm/smtp-connection/index.js +6 -0
- package/dist/esm/smtp-pool/index.d.ts +1 -0
- package/dist/esm/smtp-pool/index.js +57 -6
- package/dist/esm/smtp-pool/pool-resource.js +26 -4
- package/dist/esm/smtp-transport/index.d.ts +1 -0
- package/dist/esm/smtp-transport/index.js +47 -35
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ const MESSAGE_AUTH_KEYS = ['type', 'user', 'pass', 'accessToken', 'refreshToken'
|
|
|
21
21
|
class SMTPTransport extends EventEmitter {
|
|
22
22
|
constructor(options) {
|
|
23
23
|
super();
|
|
24
|
+
this.supportsAbortSignal = true;
|
|
24
25
|
options = options || {};
|
|
25
26
|
if (typeof options === 'string') {
|
|
26
27
|
options = {
|
|
@@ -115,13 +116,46 @@ class SMTPTransport extends EventEmitter {
|
|
|
115
116
|
* @param callback Callback function
|
|
116
117
|
*/
|
|
117
118
|
send(mail, callback) {
|
|
119
|
+
const signal = mail.data.signal;
|
|
120
|
+
let returned = false;
|
|
121
|
+
let connection;
|
|
122
|
+
let perCallAuth;
|
|
123
|
+
const cleanupPerCallAuth = () => {
|
|
124
|
+
if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
|
|
125
|
+
perCallAuth.oauth2.removeAllListeners();
|
|
126
|
+
}
|
|
127
|
+
perCallAuth = null;
|
|
128
|
+
};
|
|
129
|
+
const finish = (err, info) => {
|
|
130
|
+
if (returned) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
returned = true;
|
|
134
|
+
signal?.removeEventListener('abort', onAbort);
|
|
135
|
+
cleanupPerCallAuth();
|
|
136
|
+
connection?.close();
|
|
137
|
+
callback(err, info);
|
|
138
|
+
};
|
|
139
|
+
function onAbort() {
|
|
140
|
+
finish(errors.createAbortError(signal));
|
|
141
|
+
}
|
|
142
|
+
if (signal) {
|
|
143
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
144
|
+
if (signal.aborted) {
|
|
145
|
+
setImmediate(onAbort);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
118
149
|
// the proxy handshake, if any, counts against connectionTimeout as well
|
|
119
150
|
const connectStartedAt = Date.now();
|
|
120
151
|
this.getSocket(Object.assign({}, this.options, { connectStartedAt }), (err, socketOptions) => {
|
|
152
|
+
if (returned) {
|
|
153
|
+
socketOptions && socketOptions.connection?.destroy();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
121
156
|
if (err) {
|
|
122
|
-
return
|
|
157
|
+
return finish(err);
|
|
123
158
|
}
|
|
124
|
-
let returned = false;
|
|
125
159
|
let options = this.options;
|
|
126
160
|
if (socketOptions && socketOptions.connection) {
|
|
127
161
|
this.logger.info({
|
|
@@ -135,24 +169,9 @@ class SMTPTransport extends EventEmitter {
|
|
|
135
169
|
// only copy options if we need to modify it
|
|
136
170
|
options = Object.assign(shared.assign(false, options), socketOptions);
|
|
137
171
|
}
|
|
138
|
-
const connection = new SMTPConnection(options);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const cleanupPerCallAuth = () => {
|
|
142
|
-
if (perCallAuth && perCallAuth !== this.auth && perCallAuth.oauth2) {
|
|
143
|
-
perCallAuth.oauth2.removeAllListeners();
|
|
144
|
-
}
|
|
145
|
-
perCallAuth = null;
|
|
146
|
-
};
|
|
147
|
-
connection.once('error', err => {
|
|
148
|
-
if (returned) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
returned = true;
|
|
152
|
-
cleanupPerCallAuth();
|
|
153
|
-
connection.close();
|
|
154
|
-
return callback(err);
|
|
155
|
-
});
|
|
172
|
+
const smtp = (connection = new SMTPConnection(options));
|
|
173
|
+
smtp._connectStartedAt = connectStartedAt;
|
|
174
|
+
smtp.once('error', err => finish(err));
|
|
156
175
|
const sendMessage = () => {
|
|
157
176
|
const envelope = mail.message.getEnvelope();
|
|
158
177
|
const messageId = mail.message.messageId();
|
|
@@ -171,20 +190,17 @@ class SMTPTransport extends EventEmitter {
|
|
|
171
190
|
tnx: 'send',
|
|
172
191
|
messageId
|
|
173
192
|
}, 'Sending message %s to <%s>', messageId, recipients.join(', '));
|
|
174
|
-
|
|
193
|
+
smtp.send(envelope, mail.message.createReadStream(), (err, info) => {
|
|
175
194
|
if (returned) {
|
|
176
195
|
// the connection error handler has already reported this send
|
|
177
196
|
return;
|
|
178
197
|
}
|
|
179
|
-
returned = true;
|
|
180
|
-
cleanupPerCallAuth();
|
|
181
|
-
connection.close();
|
|
182
198
|
if (err) {
|
|
183
199
|
this.logger.error({
|
|
184
200
|
err,
|
|
185
201
|
tnx: 'send'
|
|
186
202
|
}, 'Send error for %s: %s', messageId, err.message);
|
|
187
|
-
return
|
|
203
|
+
return finish(err);
|
|
188
204
|
}
|
|
189
205
|
info.envelope = {
|
|
190
206
|
from: envelope.from,
|
|
@@ -192,7 +208,7 @@ class SMTPTransport extends EventEmitter {
|
|
|
192
208
|
};
|
|
193
209
|
info.messageId = messageId;
|
|
194
210
|
try {
|
|
195
|
-
return
|
|
211
|
+
return finish(null, info);
|
|
196
212
|
}
|
|
197
213
|
catch (E) {
|
|
198
214
|
this.logger.error({
|
|
@@ -202,27 +218,23 @@ class SMTPTransport extends EventEmitter {
|
|
|
202
218
|
}
|
|
203
219
|
});
|
|
204
220
|
};
|
|
205
|
-
|
|
221
|
+
smtp.connect(err => {
|
|
206
222
|
if (returned) {
|
|
207
223
|
return;
|
|
208
224
|
}
|
|
209
225
|
if (err) {
|
|
210
226
|
// the server closed the connection before the greeting
|
|
211
|
-
|
|
212
|
-
connection.close();
|
|
213
|
-
return callback(err);
|
|
227
|
+
return finish(err);
|
|
214
228
|
}
|
|
215
229
|
perCallAuth = this.getAuth(mail.data.auth);
|
|
216
|
-
if (perCallAuth && (
|
|
217
|
-
|
|
230
|
+
if (perCallAuth && (smtp.allowsAuth || options.forceAuth)) {
|
|
231
|
+
smtp.login(perCallAuth, err => {
|
|
218
232
|
cleanupPerCallAuth();
|
|
219
233
|
if (returned) {
|
|
220
234
|
return;
|
|
221
235
|
}
|
|
222
236
|
if (err) {
|
|
223
|
-
|
|
224
|
-
connection.close();
|
|
225
|
-
return callback(err);
|
|
237
|
+
return finish(err);
|
|
226
238
|
}
|
|
227
239
|
sendMessage();
|
|
228
240
|
});
|