我正在尝试使用邮件侦听器接收特定的电子邮件收件箱。
var MailListener = require("mail-listener-next");
var mailListener = new MailListener({
username: "user",
password: "pass",
host: "host",
port: 143, // imap port
tls: true,
connTimeout: 10000, // Default by node-imap
authTimeout: 5000, // Default by node-imap,
debug: console.log, // Or your custom function with only one incoming argument. Default: null
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
attachments: false, // download attachments as they are encountered to the project directory
//attachmentOptions: { directory: "attachments/" }, // specify a download directory for attachments
// to make server respond to other requests you may want
// to pause for 'fetchingPauseTime' fetching of the email, because it 'hangs' your app
fetchingPauseThreshold: null, // amount bytes
fetchingPauseTime: 5000 // ms to pause fetching and process other requests
});
mailListener.start(); // start listening to the box
mailListener.on("server:connected", function(){
console.log("imapConnected");
});
mailListener.on("server:disconnected", function(){
console.log("imapDisconnected");
});
mailListener.on("error", function(err){
console.log(err);
});
mailListener.on("attachment", function(attachment, email) {
if(attachment.includes(".pdf")) {
// do whatever here
console.log("message received. Executing shell script");
}
});
请注意,我为username
,password
和host
设置了虚拟值。我收到此错误消息。
[connection] Error: Error: 47043870756864:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
{ Error: 47043870756864:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:
at Socket.ondata (internal/js_stream_socket.js:64:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:145:17) source: 'socket' }
[connection] Closed
imapDisconnected
到目前为止,我已经验证用户名,密码,主机和端口都是正确的。 Openssl在1.0.1f版本上运行。我还确保安装和更新下一个邮件侦听器的依赖项。在这一点上,我确定代码本身存在问题,但我没有看到它。非常感谢任何见解。
openssl中的“错误的版本号”错误意味着客户端已禁用服务器支持的最大SSL / TLS版本。如果您自己没有禁用版本,那么有许多较旧的(现在被认为是不安全的)版本。
我建议您升级服务器上支持的受支持的TLS版本(或要求他们)。
如果您确实需要连接到此服务器,那么您应该能够连接到服务器,您可以启用旧版本的ssl / tls,直到它工作。
您可以使用openssl s_client来测试连接,以查看您需要启用的版本。
您要使用的选项包括:
-ssl2,-ssl3,-tls1,-tls1_1,-tls1_2,-no_ssl2,-no_ssl3,-no_tls1,-no_tls1_1,-no_tls1_2这些选项需要或禁用指定的SSL或TLS协议。默认情况下,初始握手使用版本灵活的方法,该方法将协商最高的相互支持的协议版本。
EG
openssl s_client -tls1 -connect www.site.com:443