Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on POP3 GetMessageHeadersAsync with Gmail #114

Closed
felixcollins opened this issue Oct 23, 2014 · 9 comments
Closed

Exception on POP3 GetMessageHeadersAsync with Gmail #114

felixcollins opened this issue Oct 23, 2014 · 9 comments

Comments

@felixcollins
Copy link

Hi, I'm not that familiar with email protocols so forgive me if I've missed something obvious.

I'm calling GetMessageHeadersAsync (MailKit 1.0.0) and I get this stack trace.

10-23 14:54:34.226 E/        (19207): MailKit.Net.Pop3.Pop3ProtocolException: Unexpected response from server: MIME-Version: 1.0
10-23 14:54:34.226 E/        (19207):   at MailKit.Net.Pop3.Pop3Engine.ReadResponse (MailKit.Net.Pop3.Pop3Command pc) [0x00000] in <filename unknown>:0 
10-23 14:54:34.226 E/        (19207):   at MailKit.Net.Pop3.Pop3Engine.Iterate () [0x00000] in <filename unknown>:0 
10-23 14:54:34.226 E/        (19207):   at MailKit.Net.Pop3.Pop3Client.GetMessagesForSequenceIds (IList`1 seqids, Boolean headersOnly, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
10-23 14:54:34.226 E/        (19207):   at MailKit.Net.Pop3.Pop3Client.GetMessageHeaders (IList`1 indexes, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
10-23 14:54:34.226 E/        (19207):   at MailKit.MailSpool+<>c__DisplayClass30.<GetMessageHeadersAsync>b__2f () [0x00000] in <filename unknown>:0 

The relevant code snippet

await client.ConnectAsync(request.EmailServerAddress, (int)request.EmailPort, request.EmailUseSSL, ct);

// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

await client.AuthenticateAsync(request.EmailUserName, request.EmailUserPassword, ct);

var count = await client.GetMessageCountAsync(ct);

var allHeaderLists = await client.GetMessageHeadersAsync(Enumerable.Range(0, count - 1).ToList(), ct);

I did have it working with an older version of MailKit using GetMessageHeaderAsync (singular).

Any ideas?

@jstedfast
Copy link
Owner

I'm probably going to need the protocol logs to diagnose this problem. Could you pass a ProtocolLogger to the Pop3Client .ctor?

@felixcollins
Copy link
Author

Connected to pops://pop.gmail.com:995/
S: +OK Gpop ready for requests from 203.86.205.98 kk16mb4935504icc
C: CAPA
S: +OK Capability list follows
S: USER
S: RESP-CODES
S: EXPIRE 0
S: LOGIN-DELAY 300
S: TOP
S: UIDL
S: X-GOOGLE-RICO
S: SASL PLAIN XOAUTH2
S: .
C: AUTH PLAIN
S: + 
C: AGxhb3V0cnlAZ21haWwuY29tAHdlYWtwYXNzd29yZA==
S: +OK Welcome.
C: CAPA
S: +OK Capability list follows
S: USER
S: RESP-CODES
S: PIPELINING
S: EXPIRE 0
S: LOGIN-DELAY 300
S: TOP
S: UIDL
S: X-GOOGLE-RICO
S: .
C: STAT
S: +OK 20 20718932
C: TOP 1 0
C: TOP 2 0
C: TOP 3 0
C: TOP 4 0
C: TOP 5 0
C: TOP 6 0
C: TOP 7 0
C: TOP 8 0
C: TOP 9 0
C: TOP 10 0
C: TOP 11 0
C: TOP 12 0
C: TOP 13 0
C: TOP 14 0
C: TOP 15 0
C: TOP 16 0
C: TOP 17 0
C: TOP 18 0
C: TOP 19 0
S: +OK message follows
S: MIME-Version: 1.0
S: x-no-auto-attachment: 1
S: Received: by 10.96.40.106; Tue, 8 Jul 2014 21:01:32 -0700 (PDT)
S: Date: Tue, 8 Jul 2014 21:01:32 -0700
S: Message-ID: <CAHwOFDw6gpW8_KW8R7cg5yNbv4E7O_j+jrCBcoVViSMjHiC6PQ@mail.gmail.com>
S: Subject: Three tips to get the most out of Gmail
S: From: Gmail Team <mail-noreply@google.com>
S: To: KG Test <laoutry@gmail.com>
S: Content-Type: multipart/alternative; boundary=20cf3074af8482c58404fdbac36b
S: 
S: .
S: +OK message follows
S: MIME-Version: 1.0
S: x-no-auto-attachment: 1
S: Received: by 10.96.40.106; Tue, 8 Jul 2014 21:01:33 -0700 (PDT)
S: Date: Tue, 8 Jul 2014 21:01:33 -0700
S: Message-ID: <CAHwOFDzTEMBrhg4T2CyhKRxNNn+9Tck8e-Qx0U23vw3ogwHsFQ@mail.gmail.com>
S: Subject: The best of Gmail, wherever you are
S: From: Gmail Team <mail-noreply@google.com>
S: To: KG Test <laoutry@gmail.com>
S: Content-Type: multipart/alternative; boundary=20cf3074d72c8812c804fdbac3c6
S: 
S: .

@jstedfast
Copy link
Owner

Thanks, this should help. Also I didn't realize GMail supports PIPELINING...

The problem, I imagine, has something to do with a bug in MailKit's PIPELINING support.

@jstedfast
Copy link
Owner

Okay, that commit should fix things... I will warn you, though, that I have not actually tested it yet.

If you could get back to me as to whether it works for you, that would be great.

@jstedfast
Copy link
Owner

I've confirmed the fix now with my gmail test account.

@felixcollins
Copy link
Author

Wow fast! Thanks for that. Sorry I didn't get back to you, I was dragged off to other things.

@jstedfast
Copy link
Owner

I pushed MailKit v1.0.1 this morning to NuGet if you are using that.

@felixcollins
Copy link
Author

1.0.1 via NuGet works for me. Thanks again...

@jstedfast
Copy link
Owner

no prob, glad it works :-)

weltmeyer pushed a commit to weltmeyer/MailKit that referenced this issue Nov 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants