0

Here is my code but its not working for sent message folder. I have tried using node-imap and node-inbox and node-maillistner2 module but none of them were able to retrieve the sent message box. I am using ymail account and imap server.

  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);
        });
      });

    });
  });
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

You can use mail-listner2 lib for the same, below is the code snippet for reading inbox messages, the same would work with send box too, replace INBOX with SENT. Let me know the progress.

 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;


}
Rohit
  • 3,314
  • 1
  • 13
  • 15