Accessing emails from gmail using IMAP ( javamail API)

后端 未结 5 1745
無奈伤痛
無奈伤痛 2020-12-13 04:20

I am trying to access emails from Gmail accounts through IMAP with the help of the JavaMail API. I was wondering why the code works for one email account but doesn\'t work f

5条回答
  •  情深已故
    2020-12-13 05:11

    It works this way (It looks like it doesn't work with POP3, but it works with IMAP):

         Properties props = new Properties();
         props.put("mail.store.protocol", "imaps");
         Session session = Session.getDefaultInstance(props, null);
         Store store = session.getStore("imaps");
         store.connect("imap.gmail.com", [theMailAccount@gmail.com], [thePasswordOrAppPassword]);
    
         // You possibly will have to use [Google Mail]/All Mail instead
         Folder inbox = store.getFolder("[Gmail]/All Mail");
    

提交回复
热议问题