title: Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure)
body: <p>I am trying to connect to my mail box using the java mail api based on imap protocol. I check and for sure I inserting the correct parameters. This is the following exception that I got:</p>
  
  <blockquote>
    <p>[ALERT] Please log in via your web browser: <a href="https://support.google.com/mail/accounts/answer/78754" rel="nofollow">https://support.google.com/mail/accounts/answer/78754</a> (Failure)</p>
  </blockquote>
  
  <p>I do not know why it is happens in addition I enabled the imap option in my gmail account settings.</p>
  
  <p>Ihis is my code:</p>
  
  <pre><code> Properties protocol = new Properties();
   protocol.setProperty("mail.store.protocol", "imaps");
  
   try{
        Session session = Session.getInstance(protocol, null);
        Store store = session.getStore();
        String host = prop.getProperty("host");
        String email = prop.getProperty("username");
        String password = prop.getProperty("password");
        store.connect(host, email, password);
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_ONLY);
        int messageCount = inbox.getMessageCount();
        model.addAttribute("msg","number of mails"+" "+messageCount);
        Message[] messages = inbox.getMessages();
        PrintWriter writer = new PrintWriter(username+".txt", "UTF-8");
  
        for(int i=0;i&lt;messageCount || prop.getProperty("status").equals(status.RUNNING.toString()) ;i++ ){
            model.addAttribute("msg","Reading Mails");
            Multipart mp = (Multipart) messages[i].getContent();
            BodyPart bp = mp.getBodyPart(0);
            writer.println("From:"+ messages[i].getFrom()+" "+"Subject:"+messages[i].getSubject()+" "+"Message:"+bp.getContent());
            prop =  loadProperties(username+".properties");
         }
         writer.close();
         inbox.close(true);
         store.close();
  
      }catch (Exception e){
                      model.addAttribute("msg","Exception:"+e.getMessage());
  }
  </code></pre>