Comments (2)
There is a working implementation on top of browserbox that accumulates many of its features in a somewhat opinionated high-level api, so you might want to have a look at that: https://github.com/whiteout-io/imap-client
(We did not really get around to write a proper documentation for the imap-client), but you should be able to figure it out pretty quickly from the inline documentation)
Regarding your code examples: client.connect();
is not synchronous, you need to wait for the onauth
callback. Here's an example. Otherwise your queries end up somewhere in oblivion.
Second: useSSL
is deprecated, you should use useSecureTransport
instead. I'll adapt the README.
Please let me know if that helped.
from emailjs-imap-client.
The module is not synchronous, just as Felix already stated – you have to wait for the callback before you can make the next command.
What happens with your code is the following:
S: * OK Gimap ready for requests from X.X.X.X j1mb3779317lae ← session idendifier
C: W1 LIST "" "*" ← already calling LIST command even though you're not logged in
S: W1 BAD Unknown command j1mb3779317lae ← error response with session idendifier
the command is 'unknown' because LIST is
available only in the 'authenticated' state
To fix this, your code should be like this:
client.connect();
client.onauth = function() {
client.listMailboxes(function(err, mailboxes) {
console.log(err || mailboxes);
client.selectMailbox(mailbox, function(err, mailbox) {
console.log(err || 'Mailbox was successfully changed to ' + mailbox);
});
});
};
In this case the commands are completely different:
S: * OK Gimap ready for requests from X.X.X.X j1mb3779317lae
C: W1 CAPABILITY
S: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ...
S: W1 OK Thats all she wrote! j1mb3779317lae
C: W2 ID NIL
S: * ID ("name" "GImap" "vendor" "Google, Inc." ...
S: W2 OK Success j1mb3779317lae
C: W3 login "[email protected]" "some.password"
S: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE ...
S: W3 OK [email protected] Some Email authenticated (Success)
C: W4 LIST "" "*" ← now we send the LIST after successful auth
S: * LIST (\Noselect \HasChildren) "/" "[Gmail]" ← and no error anymore
...
Remember that in addition of onauth
you should also set onerror
handler, otherwise you might end up with uncaught errors, and the onclose
handler to detect if the connection is already closed.
I'll close this issue as it is not a bug but feel free to ask if you have any further questions.
from emailjs-imap-client.
Related Issues (20)
- how to get new messages first on listMessages? HOT 1
- UnhandledPromiseRejectionWarning: Error: IDLE not allowed now HOT 3
- How to Listen for new emails
- An in-range update of webpack-cli is breaking the build 🚨 HOT 2
- getaddrinfo ENOTFOUND imap.cox.net HOT 3
- emailjs problem with async methods
- How can I get from all messages the attachments?
- An in-range update of pako is breaking the build 🚨 HOT 2
- Can't remove, add or set \Seen
- Self signed certificate HOT 8
- No envelope HOT 1
- How to add other parameters
- _tls2.default.connect and help wanted
- Helping
- 8bit support HOT 1
- emailjs.org website not available
- UID passed in and UID received are not equal HOT 1
- Feature: Search for multiple HEADER fields (AND)
- Please update NPM package HOT 2
- Stop condition for arriving packets is not sufficient.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emailjs-imap-client.