0

我正在使用 npm 的邮件侦听器包来获取自特定日期以来的所有收件箱消息。

这是我获取收件箱消息的代码,

'listener':function(credit,userid = this.userId,date = (new Date()).toString()){
        if(credit.port === "143" || credit.port === "993") {
            let mailListener2 = new MailListener({
                username: credit.user,
                password: credit.password,
                host: credit.host,
                port: credit.port, // imap port
                tls: (credit.port === "993"),
                connTimeout: 10000, // Default by node-imap
                authTimeout: 5000, // Default by node-imap,
                debug: null, // Or your custom function with only one incoming argument. Default: null
                tlsOptions: {rejectUnauthorized: false},
                mailbox: "INBOX", // mailbox to monitor
                searchFilter: [["SINCE", date]],
                markSeen: false, // 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: {streamAttachments: true}, // options to be passed to mailParser lib.
                attachments: false, // download attachments as they are encountered to the project directory
                attachmentOptions: {directory: "/data/attachments/"} // specify a download directory for attachments
            });

            mailListener2.on("server:connected", Meteor.bindEnvironment(function () {
                console.log("imapConnected");
            }));

            mailListener2.on("server:disconnected", Meteor.bindEnvironment(function () {
                console.log("imapDisconnected");
            }));

            mailListener2.on("error", Meteor.bindEnvironment(function (err) {
                console.log("error listener", err);
            }));
            mailListener2.on("mail", Meteor.bindEnvironment(function (mail) {
                console.log("receive message");
            }));

            mailListener2.start();
        }else if(credit.port === "587" || credit.port === "465"){
            if not imap ....
        }
        return true;
    },

如果开始或在特定日期开始,我想允许我的用户只选择选项。所以我的问题是,我不知道如何从一开始就获取所有收件箱消息。我怎样才能做到这一点?

我还需要使用 SINCE 吗?

4

1 回答 1

0

- 如果您想获取所有收件箱消息,您可以输入如下选项:searchFilter: ['UNSEEN']。

- 如果您想从特定日期获取所有消息,您可以使用这样的选项(使用 moment lib): searchFilter: ['UNSEEN', ['SINCE', moment(DATE_USER).format('ll')]] ,

于 2018-06-08T17:50:58.167 回答