0

In this i am trying to access Email box using IMAPS protocol.

public static void main(String[] args) throws MessagingException {
    Properties props = new Properties();
    props.put("mail.store.protocol", "imaps");
    props.put("mail.imaps.port", "993");
    props.put("mail.imaps.starttls.enable", "true");
    Session session = Session.getDefaultInstance(props);
    Store store = session.getStore("imaps");

    store.connect("imap-mail.outlook.com", "emailid@domain.com","xxxx");
    Folder elisa = store.getFolder("Inbox");
    System.out.println("No of unread Mail " + elisa.getUnreadMessageCount());
}

Error which i am getting is :

Exception in thread "main" javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid username or password.
    at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at sid.test.email.EmailMain.main(EmailMain.java:21)
Ken Bekov
  • 13,696
  • 3
  • 36
  • 44
Siddharth Singh
  • 65
  • 2
  • 12

1 Answers1

0

According to https://www.lifewire.com/outlook-imap-server-settings-1170672 you should use your full Outlook.com email address (not an alias). Are you using the outlook.com email address, not emailid@domain.com ?

rob2universe
  • 7,059
  • 39
  • 54