0

这是我的代码,但它不适用于已发送的消息文件夹。我曾尝试使用 node-imap 和 node-inbox 和 node-maillistner2 模块,但它们都无法检索已发送的消息框。我正在使用 ymail 帐户和 imap 服务器。

  var inbox = require("inbox");

  console.log(mailLogin);
  var client = inbox.createConnection(false, mailLogin.imapserver, {
    secureConnection: mailLogin.isTlsEnabled,
    auth: {
      user: mailLogin.email,
      pass: mailLogin.password
    }
  });

  client.connect();
  client.listMailboxes({all:true}, function (error, info) {
    console.log(info)
  })

  client.on("connect", function () {
    client.openMailbox("INBOX/SENT", function (error, info) {
      if (error) throw error;

      client.listMessages(-10, function (err, messages) {
        messages.forEach(function (message) {
          console.log(message.UID + ": " + message.title);
        });
      });

    });
  });
4

1 回答 1

0

您也可以使用 mail-listner2 lib,下面是读取收件箱消息的代码片段,同样适用于发送框,将 INBOX 替换为 SENT。让我知道进展。

 emailbody(userid, password) {



        var deferred = protractor.promise.defer();

        var MailListener = require("mail-listener2");
        var mailListener = new MailListener({
            username: userid,
            password: password,
            host: "imap.gmail.com",
            //host: "imap.gmx.com",
            port: 993, // imap port
            tls: true,
            connTimeout: 25000, // Default by node-imap
            authTimeout: 10000, // 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: ["UNSEEN"], // 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: { streamAttachments: true }, // options to be passed to mailParser lib.
            attachments: true, // download attachments as they are encountered to the project directory
            attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments

        });

        global.mailListener = mailListener;

        mailListener.start();


        mailListener.on("mail", function (mail, seqno, attributes) {
            console.log('email received!');
            global.mailListener.stop();
            deferred.fulfill(mail);
        });

        mailListener.on("error", function (err) {
            console.log('Email reading error');
            global.mailListener.stop();
            deferred.reject(err);
        });
    return deferred.promise;


}
于 2017-12-07T05:44:33.360 回答