我正在构建一个应用程序,将使用AWS SES发送电子邮件通过SMTP。我已经正确地配置了一个域,并确认我可以使用AWS从该域发送电子邮件。我已经创建了SMTP凭据,并确保IAM用户配置了正确的权限。我编写了一个使用诺德迈勒发送电子邮件的测试脚本。
测试脚本在我的家庭网络上使用我的个人开发机器成功运行,但是当使用我的公司客户端在我的家庭网络上发布的开发笔记本时,这个脚本将无法工作。公司笔记本电脑运行许多安全工具,包括ZScaler。我还知道,由于ZScaler服务,必须将NPM设置为使用自签名证书(命令为npm config set cafile {CA_FILEPATH}
)。
我不知道为什么这个脚本不能在公司的笔记本电脑上工作,我也很感激你能帮我弄清楚下一步该做什么。
下面是剧本:
'use strict';
const nodemailer = require('nodemailer');
const runtest = async function() {
console.debug('Creating the SMTP transport');
const transporter = nodemailer.createTransport({
host: 'email-smtp.us-west-2.amazonaws.com',
port: 465,
secure: true,
auth: {
user: 'myusername',
pass: 'mypassword',
},
});
console.debug('Building mail options');
const mailOptions = {
from: 'me@example.com',
to: 'you@example.com',
subject: 'subject',
text: 'body',
html: '<h1>Hi</h1',
};
console.debug('Sending mail...');
const info = await transporter.sendMail(mailOptions);
console.debug(`Sent mail. Info: ${JSON.stringify(info, null, 2)}`);
console.info('Message sent!');
};
runtest().catch(console.error);
在公司笔记本电脑上运行时,结果如下:
Creating the SMTP transport
Building mail options
Sending mail...
Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:200:27) {
errno: 'ECONNRESET',
code: 'ESOCKET',
syscall: 'read',
command: 'CONN'
}
我尝试过的事情:
rejectUnauthorized: false
)并指定TLS版本openssl
的连接。我运行了这个命令openssl s_client -connect email-smtp.us-west-2.amazonaws.com:465
,这就是结果(看起来不错):CONNECTED(0000021C)
write:errno=10054
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 336 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
发布于 2020-08-29 21:20:31
在我的例子中,是节点版本导致了这个错误。我已经将我的节点版本升级到v12.x来解决这个问题。
https://stackoverflow.com/questions/63649036
复制相似问题