有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

smtp试图使用java在Gmail中搜索主题为的邮件

我公司的邮件域是Gmail,我需要使用主题行搜索邮件。我写了下面的代码,但Gmail没有使用正确的用户id和密码连接

     public static void getMail() {
                 Scanner sc = new Scanner(System.in);
                 final String m10 = "abc@abc.com";   
                 final String n10 = "abcd";
                 String host = "absmtp.abc.com"; 
                 try
                 {
                 Properties pro1 = new Properties();   
                 pro1.put("mail.smtp.host", host);    
                 pro1.put("mail.smtp.socketFactory.port", "465");
                 MailSSLSocketFactory socketFactory= new MailSSLSocketFactory();
                    socketFactory.setTrustAllHosts(true);
                    pro1.put("mail.imaps.ssl.socketFactory", socketFactory);
              //   pro1.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");  
               //  pro1.put("mail.smtp.auth", "true");   
                 pro1.put("mail.smtp.port", "465");  
             Session session = Session.getDefaultInstance(pro1); 
                 Store store = session.getStore("imaps");  
                 store.connect(host, m10, n10); 
                 Folder folderbox = store.getFolder("INBOX");
                 folderbox.open(Folder.READ_ONLY);   
                 SearchTerm search = new SearchTerm(){

                     @Override
                     public boolean match(Message message) {
                         try
                         {
                             if(message.getSubject().contains("") ) 
                             {
                                 return true;
                             }
                         }
                         catch(Exception e)
                         {
                             System.err.println(e.getMessage());
                         }
                         return false;
                     }

                 };

                 Message[] found = folderbox.search(search);

                 int length = found.length;
                 for(int i = 0;i<found.length;i++)
                 {
                     Message mess1 = found[i];
                     System.out.println("->Message Number > "+i);
                     System.out.println("->Message Subject >"+mess1.getSubject());
                 }
                 folderbox.close(true);
                 store.close();
             }
                 catch(Exception e)
                 {
                     System.err.println(e.getMessage());
                 }
                
               }

未连接并给出错误:

Couldn't connect to host, port: abc@abc.com, 993; timeout -1.


共 (0) 个答案