@nest-omni/core 4.1.3-32 → 4.1.3-33
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.
|
@@ -46,6 +46,14 @@ let EmailLogProvider = EmailLogProvider_1 = class EmailLogProvider {
|
|
|
46
46
|
? !this.options.smtpIgnoreTLSError
|
|
47
47
|
: true,
|
|
48
48
|
},
|
|
49
|
+
// 连接池配置
|
|
50
|
+
pool: true,
|
|
51
|
+
maxConnections: 5,
|
|
52
|
+
maxMessages: 10,
|
|
53
|
+
// 超时配置
|
|
54
|
+
connectionTimeout: 10000, // 10秒连接超时
|
|
55
|
+
greetingTimeout: 5000, // 5秒握手超时
|
|
56
|
+
socketTimeout: 10000, // 10秒socket超时
|
|
49
57
|
};
|
|
50
58
|
if (this.options.smtpUsername || this.options.smtpPassword) {
|
|
51
59
|
config.auth = {
|
|
@@ -76,35 +84,67 @@ let EmailLogProvider = EmailLogProvider_1 = class EmailLogProvider {
|
|
|
76
84
|
});
|
|
77
85
|
}
|
|
78
86
|
/**
|
|
79
|
-
* Send log email
|
|
87
|
+
* Send log email with automatic retry on connection failure
|
|
80
88
|
*/
|
|
81
89
|
sendLogEmail(params) {
|
|
82
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
var _a, _b, _c;
|
|
92
|
+
const maxRetries = 2;
|
|
93
|
+
let lastError = null;
|
|
94
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
95
|
+
try {
|
|
96
|
+
if (!this.transporter) {
|
|
97
|
+
this.initializeTransporter();
|
|
98
|
+
}
|
|
99
|
+
const mailOptions = {
|
|
100
|
+
from: params.from,
|
|
101
|
+
to: params.to.join(', '),
|
|
102
|
+
subject: params.subject,
|
|
103
|
+
};
|
|
104
|
+
if (params.cc && params.cc.length > 0) {
|
|
105
|
+
mailOptions.cc = params.cc.join(', ');
|
|
106
|
+
}
|
|
107
|
+
if (params.html) {
|
|
108
|
+
mailOptions.html = params.html;
|
|
109
|
+
}
|
|
110
|
+
else if (params.text) {
|
|
111
|
+
mailOptions.text = params.text;
|
|
112
|
+
}
|
|
113
|
+
const info = yield this.transporter.sendMail(mailOptions);
|
|
114
|
+
this.logger.debug(`Log email sent to ${params.to.join(', ')} - Message ID: ${info.messageId}`);
|
|
115
|
+
return;
|
|
94
116
|
}
|
|
95
|
-
|
|
96
|
-
|
|
117
|
+
catch (error) {
|
|
118
|
+
lastError = error;
|
|
119
|
+
// Check if this is a connection error that can be retried
|
|
120
|
+
const isConnectionError = error.code === 'ECONNECTION' ||
|
|
121
|
+
error.code === 'ETIMEDOUT' ||
|
|
122
|
+
error.code === 'ECONNRESET' ||
|
|
123
|
+
((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Connection closed')) ||
|
|
124
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('socket hang up')) ||
|
|
125
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Unexpected socket close'));
|
|
126
|
+
if (isConnectionError && attempt < maxRetries) {
|
|
127
|
+
this.logger.warn(`Email send failed (attempt ${attempt}/${maxRetries}): ${error.message}. Reinitializing connection...`);
|
|
128
|
+
// Close existing transporter and create a new one
|
|
129
|
+
if (this.transporter) {
|
|
130
|
+
try {
|
|
131
|
+
this.transporter.close();
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
// Ignore close errors
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
this.transporter = null;
|
|
138
|
+
// Wait a bit before retrying
|
|
139
|
+
yield new Promise((resolve) => setTimeout(resolve, 500));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.logger.error(`Failed to send log email after ${attempt} attempt(s): ${error.message}`, error.stack);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
97
145
|
}
|
|
98
|
-
else if (params.text) {
|
|
99
|
-
mailOptions.text = params.text;
|
|
100
|
-
}
|
|
101
|
-
const info = yield this.transporter.sendMail(mailOptions);
|
|
102
|
-
this.logger.debug(`Log email sent to ${params.to.join(', ')} - Message ID: ${info.messageId}`);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
this.logger.error(`Failed to send log email: ${error.message}`, error.stack);
|
|
106
|
-
throw error;
|
|
107
146
|
}
|
|
147
|
+
throw lastError;
|
|
108
148
|
});
|
|
109
149
|
}
|
|
110
150
|
/**
|
package/package.json
CHANGED