Unable to retrieve emails based on subject line using Java Mail API -


public class testemail { java.lang.comparable c[]; properties properties = null; private session session = null; private store store = null; private folder inbox = null; private string username = "xxx@gmail.com";  // private string password = "xxx"; public testemail() {  }  public void readmails() throws exception {     properties = new properties();     properties.setproperty("mail.host", "imap.gmail.com");     properties.setproperty("mail.port", "995");     properties.setproperty("mail.transport.protocol", "imaps");     session = session.getinstance(properties,             new javax.mail.authenticator() {         protected passwordauthentication getpasswordauthentication() {             return new passwordauthentication(username, password);         }     });           store = session.getstore("imaps");         store.connect();         inbox = store.getfolder("inbox");         inbox.open(folder.read_only);          //message messages[] = inbox.search(new flagterm(new flags(flag.seen), false));         message messages[]=inbox.getmessages();     //  system.out.println("number of mails = " + messages.length);             ( message message : messages ) {             system.out.println("subject: "+ message.getsubject());             if(message.getsubject().tostring()=="suppliers match search: suto in future mode")             {             address[] = message.getfrom();             system.out.println("-------------------------------");             system.out.println("date : " + message.getsentdate());             //system.out.println("from : " + from[0]);             //system.out.println("subject: " + message.getsubject());             //system.out.println("content :");              object content = message.getcontent();             multipart multipart = (multipart) content;             //procesmultipart(multipart);              system.out.println("--------------------------------");             }             else             {                 system.out.println("not found");             }         }         inbox.close(true);         store.close();   } 

output:

   subject: suppliers match search: test 13 mar 2012 automotive    not found    subject: suppliers match search: suto in future mode    not found    subject: suppliers match search: ttt    not found    subject: suppliers match search:    not found    subject: suppliers match search: 123    not found    subject: suppliers match search: search1    not found    subject: suppliers match search: jan 28 vani    not found    subject: sign-in attempt prevented    not found    subject: stay more organised gmail's inbox    not found 

i trying filter out email subject line :"suppliers match search: suto in future mode" above program unable locate thought email available. kindly :) thanks

try replace == .equals() method in if(message.getsubject().tostring()=="suppliers match search: suto in future mode")

fyi this answer, shortly it's this: == tests reference equality (whether same object) while .equals() compares value equality (whether logically "equal") , that's case. so, if want test whether 2 strings have same value should use .equals().


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -