登录多个Gmail帐户,使用imaps读取java中收件箱中的邮件

时间:2015-07-28 07:21:24

标签: java gmail-imap javax.mail

我是初学者, 我正在编写一个程序,该程序登录到我的g-mail帐户并检查收件箱中的邮件。 要做到这一点,我正在使用imaps ("imaps.gmail.com")。 但是我的问题是登录所有帐户时,逐个检查其中的消息。

  

计划报告错误/种类:   javax.mail.AuthenticationFailedException:[ALERT]请通过登录   你的网络浏览器:一些网址(失败)imaps:xxxx@gmail.com为   第二个和其他帐户...

据此我所理解的是,我没有关闭会议,存储得当。因此,程序无法检入相应的第二个和其他邮件帐户。 有人帮忙(有澄清)..

我的代码架构:

public class InboxRead {

public static boolean release = false;
private Session session = null;

public void checkInbox(String username, String password) {
    // logging into account using imaps..

    Properties props = System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");
        session = Session.getDefaultInstance(props, null);
        store = session.getStore("imaps");
        store.connect("imap.gmail.com", username, password);
        System.out.println(store);

        // reading inbox... closing all folders here

        store.close();
        session = null;
        release = true;

}

public static void main(String[] args) {

for(;;) { // gives no of accounts with credentials..
    do {
        String username = "xxx@gmail.com";
        String password = "xxxx";

        InboxRead.checkInbox(username, password);
    } while(release);

}
}

}

...

1 个答案:

答案 0 :(得分:0)

它是Google网关引发的错误。 Google在配置文件访问甚至邮件访问方面都保持高安全性,但即使这样也可以由用户使用以下链接Google secure control

进行控制

使用您的Google帐户转到该链接,然后选择“开启”,然后尝试执行您的计划。