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);
for ( Message message : messages ) {
System.out.println("Subject: "+ message.getSubject());
if(message.getSubject().toString()=="Suppliers that match your search: suto in future mode")
{
Address[] from = 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 that match your search: Test 13 mar 2012 Automotive
not found
Subject: Suppliers that match your search: suto in future mode
not found
Subject: Suppliers that match your search: ttt
not found
Subject: Suppliers that match your search:
not found
Subject: Suppliers that match your search: 123
not found
Subject: Suppliers that match your search: Search1
not found
Subject: Suppliers that match your search: Jan 28 US by vani
not found
Subject: Sign-in attempt prevented
not found
Subject: Stay more organised with Gmail's inbox
not found
I am trying to filter out email with the subject line :"Suppliers that match your search: suto in future mode" the above program is unable to locate it even thought the email is available. kIndly help :) thanks