无法使用IMAPS协议访问电子邮箱

时间:2017-01-09 10:24:21

标签: java email imap

在此我尝试使用IMAPS协议访问电子邮箱。

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());
}

我得到的错误是:

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)

1 个答案:

答案 0 :(得分:0)

根据https://www.lifewire.com/outlook-imap-server-settings-1170672 您应该使用完整的 Outlook.com 电子邮件地址(不是别名)。 您使用的是outlook.com电子邮件地址,而不是emailid @ domain.com 吗?