Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2. String userName = "mncjhc@gmail.com";
  3. String password = "ckjbc";
  4. EmailVerificationPage searcher = new EmailVerificationPage();
  5. String subjectKeyword = "New Registration – Successful";
  6. String fromEmail="djhgdd@gmail.com";
  7. String bodySearchText ="You have successfully register to our services";
  8.  
  9. searcher.searchEmail(userName, password,subjectKeyword,fromEmail, bodySearchText);
  10. }
  11.  
  12. public boolean searchEmail(String userName,String password, final String subjectKeyword, final String fromEmail, final String bodySearchText) throws IOException {
  13. Properties properties = new Properties();
  14. boolean val = false;
  15. // server setting
  16. properties.put("mail.store.protocol", "imap");
  17. properties.put("mail.imap.host", "imap.gmail.com");
  18. properties.put("mail.imap.port", 143);
  19.  
  20. // SSL setting
  21. properties.setProperty("mail.imap.socketFactory.class","javax.net.ssl.SSLSocketFactory");
  22. properties.setProperty("mail.imap.ssl.enable", "true");
  23. properties.setProperty("mail.imap.socketFactory.fallback", "false");
  24. properties.setProperty("mail.imap.socketFactory.port",String.valueOf(143));
  25. properties.put("mail.imaps.ssl.checkserveridentity", "false");
  26. properties.put("mail.imaps.ssl.trust", "*");
  27. properties.put("mail.imap.fetchsize", "519200");
  28. properties.put("mail.imaps.connectiontimeout", 1000);
  29. properties.put("mail.imaps.connectionpooltimeout", 1000);
  30. properties.put("mail.imaps.onTimeout", 1000);
  31.  
  32. Session session = Session.getDefaultInstance(properties,
  33. new javax.mail.Authenticator(){
  34. protected PasswordAuthentication getPasswordAuthentication() {
  35. return new PasswordAuthentication(
  36. userName, password);// Specify the Username and the PassWord
  37. }
  38. });
  39.  
  40. try {
  41. // connects to the message store
  42. Store store = session.getStore("imap");
  43. store.connect("imap.gmail.com", Integer.parseInt("143"), userName, password);
  44. System.out.println("Connected to Email server….");
  45. // opens the inbox folder
  46. Folder folderInbox = store.getFolder("INBOX");
  47. folderInbox.open(Folder.READ_ONLY);
  48. folderInbox.close(false);
  49. store.close();
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement