question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fetch error: Error: The specified message set is invalid. !!

See original GitHub issue

I am trying the following code to fetch Hotmail/outlook emails :

var Imap = require("imap"),
  inspect = require("util").inspect;

var imap = new Imap({
  user: "myemail@hotmail.com",
  password: "mypassword",
  host: "imap-mail.outlook.com",
  port: 993,
  tls: true
});

function openInbox(cb) {
  imap.openBox("INBOX", true, cb);
}

imap.once("ready", function() {
  openInbox(function(err, box) {
    if (err) throw err;
    var f = imap.seq.fetch(`*`, {
      bodies: "HEADER.FIELDS (FROM TO SUBJECT DATE)",
      struct: true
    });
    f.on("message", function(msg, seqno) {
      console.log("Message #%d", seqno);
      var prefix = "(#" + seqno + ") ";
      msg.on("body", function(stream, info) {
        var buffer = "";
        stream.on("data", function(chunk) {
          buffer += chunk.toString("utf8");
        });
        stream.once("end", function() {
          console.log(
            prefix + "Parsed header: %s",
            inspect(Imap.parseHeader(buffer))
          );
        });
      });
      msg.once("attributes", function(attrs) {
        console.log(prefix + "Attributes: %s", inspect(attrs, false, 8));
      });
      msg.once("end", function() {
        console.log(prefix + "Finished");
      });
    });
    f.once("error", function(err) {
      console.log("Fetch error: " + err);
    });
    f.once("end", function() {
      console.log("Done fetching all messages!");
      imap.end();
    });
  });
});

imap.once("error", function(err) {
  console.log(err);
});

imap.once("end", function() {
  console.log("Connection ended");
});

imap.connect();

But, I’m getting the following error :

Fetch error: Error: The specified message set is invalid.
Done fetching all messages!
Connection ended

@mscdex please help !!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ahmedisam99commented, Apr 14, 2019

@mscdex Done, the problem was with the source range, I used imap.seq.fetch("*", options) and worked with gmail but it didn’t work with hotmail/outlook so i changed it to “1:*” Relates #615

1reaction
mscdexcommented, Apr 14, 2019

Ah ok, yeah not all server IMAP implementations behave correctly, especially outlook/exchange from what I’ve seen in the past.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expunge caused "BAD Protocol Error: "Specified message set ...
Hi there. I have a bit trouble with JavaMail 1.4.1. I think, I use it in the wrong way, but I get no...
Read more >
imap - "The specified message set is invalid (NO)" Exception ...
First I am processing all the messages I get back in the Bounce Result collection and collecting all the Sequence ID's I Want...
Read more >
Server Replied: No the specified message set is invalid. - MSDN
im: <= 'A7 NO The specified message set is invalid. ' Fetch error: Error: The specified message set is invalid. Done fetching all...
Read more >
IMAP FETCH (Exchange) returns "Invalid message set in ...
The mail server responded: Protocol Error: "Invalid message set in FETCH command".' Closing all Mozilla windows and restarting enables mail to function ...
Read more >
IMAP Error: command FETCH: Invalid messageset
Error in IMAP command FETCH: Invalid messageset: This error is caused by a well-known bug in the IMAP implementation used by your email...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found