【发布时间】:2021-11-03 07:36:18
【问题描述】:
我需要创建一个可能有 100 万封电子邮件的电子邮件服务器。 我想收听所有的电子邮件帐户,基本上是收听收到的电子邮件(每天大约 20k)
我有以下 node.js 脚本,它只收听一封电子邮件。 但我想收听所有所有电子邮件帐户的所有新电子邮件。 我怎样才能做到这一点?欢迎任何想法。 或者是否有任何其他提供该功能的电子邮件服务器。
我的目标是能够在服务器上有新电子邮件时触发事件并保存该电子邮件的附件。
var MailListener = require("mail-listener4");
var mailListener = new MailListener({
username: 'something@example.com',
password: 'password',
host: 'mail.example.com',
port: 993, // 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
searchFilter: ["ALL"], // the search filter being used after an IDLE notification has been retrieved
markSeen: true, // all fetched email willbe marked as seen and not fetched next time
fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
mailParserOptions: {stream: true}, // options to be passed to mailParser lib.
attachments: true, // download attachments as they are encountered to the project directory
attachmentOptions: { directory: "attachments/" } ,
searchFilter: ["UNSEEN"],
markSeen: true, // specify a download directory for attachments
});
mailListener.start();
mailListener.on("server:connected", function(){
console.log("imapConnected");
});
mailListener.on("mailbox", function(mailbox){
console.log("Total number of mails: ", mailbox.messages.total); // this field in mailbox gives the total number of emails
});
mailListener.on("server:disconnected", function(){
console.log("imapDisconnected");
});
mailListener.on("error", function(err){
console.log(err);
});
mailListener.on("mail", function(mail, seqno, attributes){
});
mailListener.on("attachment", function(attachment){
console.log(attachment.path);
});
如果需要,我可以详细说明我的要求。
【问题讨论】:
-
如果您要托管服务器,最好将脚本插入 SMTP 服务器。大多数 unix 风格的服务器都支持在邮件路径中放置“过滤器”或类似的东西,这将允许您在通过该服务器的每封传入电子邮件上触发某些内容。试图通过 IMAP 获取它们是一场失败的战斗。
-
您是否需要创建一个完整的邮件服务器来满足您的要求,或者您是否正在使用某些提供商(gmail、hotmail、yahoo、yandex)并且只需要在邮件到达时收到一种通知您的用户收件箱?
-
我需要创建整个电子邮件服务器,因为我必须为每个订阅者分配一个电子邮件帐户,然后每当我们需要存储的任何电子邮件中有新电子邮件时。