Gmail POP3 not getting all messages in Java application

后端 未结 2 1935
悲&欢浪女
悲&欢浪女 2021-01-12 05:35

I have enabled POP3 settings for my gmail. I am able to connect to the POP3 store using my password in a Java app. I have around 10k messages in my inbox.

When I cal

2条回答
  •  天命终不由人
    2021-01-12 06:06

    Not a real answer, but I got around this by using Mailkit's IMAP. Also, this is C#, not Java code, but maybe it can help people running into the same problem:

          var emails = new List();
    
          using (var client = new ImapClient())
          {
            client.Connect("imap.gmail.com", _smtpConfig.SSLIMAPPort, SecureSocketOptions.SslOnConnect);
            client.ServerCertificateValidationCallback = (s, c, h, e) => true;
            client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            client.Authenticate(smtpConfig.PopUsername, smtpConfig.PopPassword);
    
            client.Inbox.Open(FolderAccess.ReadWrite);
            var items = client.Inbox.Fetch(0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure);
    
            foreach (var item in items)
            {
              if (item.TextBody != null)
              {
                var mime = (TextPart)client.Inbox.GetBodyPart(item.UniqueId, item.TextBody);
                var text = mime.Text;
    
                var email = new EmailMessage
                {
                  Body = text
                };
    
                emails.Add(email);
              }
            }
    
            client.Disconnect(true);
          }
    
          return emails;
    
    Thanks to jstedfast - it was all done using his docs.
    

提交回复
热议问题