My company mail domain is Gmail , and I need to search a mail using subject line. I have written below code but Gmail is not connecting with correct user id and password.
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()); } }
is not connecting and giving error :
https://stackoverflow.com/questions/65402185/trying-to-search-a-mail-with-subject-in-gmail-using-java December 22, 2020 at 09:35AMCouldn't connect to host, port: abc@abc.com, 993; timeout -1.
没有评论:
发表评论