JavaMail flagging problems

Ads

 
 

Share on Google+Share on Google+

vidhu
JavaMail flagging problems
1 Answer(s)      7 years ago
Posted in : JavaMail
Hi everyone, I am working on receiving a mail currently. I use a substring "status" to search for the mail's subject line and read only those mails which have this as the subject line.
My problem is, every time i run the program, the old mails are also displayed. how to flag the mails as 'read' and read only the unread mails the next time i run the program... ? here is my source code.

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.search.*;


public class MessageRead {

public static void receive(String smtpHost, String user,
String password, String subjectSubstringToSearch){
Session session = Session.getInstance(new Properties());

try {
Store store = session.getStore("pop3");
store.connect(smtpHost, user, password);
// Get "INBOX"
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
int count = folder.getMessageCount();
System.out.println(count + " total messages");

// Search for e-mails by some subject substring
String pattern = subjectSubstringToSearch;
SubjectTerm subterm = new SubjectTerm(pattern);
Message [] found = folder.search(subterm);

System.out.println(found.length +
" messages matched Subject pattern \"" +
pattern + "\"");

for (int integer = 0; integer < found.length; integer++) {
Message message = found[integer];
Date date = message.getSentDate();
Address [] from = message.getFrom();
String subj = message.getSubject();
String mimeType = message.getContentType();
System.out.println(date + "\t" + from[0] + "\t" +
subj + "\t" + mimeType);
//here add the code for flagging


/*if (message[i].isSet(Flags.Flag.SEEN)) {
System.out.println("Read");
} */
Object o = message.getContent();
if (o instanceof String) {
System.out.println("--This is a String Body part--");
System.out.println((String)o);
}
else if (o instanceof Multipart) {
System.out.println("--This is a Multipart Message--");
Multipart multipart = (Multipart)o;
int count3 = multipart.getCount();
System.out.println("It has " + count3 +
" BodyParts in it!");
for (int j = 0; j < count3; j++) {
BodyPart b = multipart.getBodyPart(j);
/*System.out.println( "BodyPart " + (j + 1) +
" is of MimeType " + mimeType); */

Object o2 = b.getContent();
if (o2 instanceof String) {
System.out.println("--This the mail's Body--");
System.out.println((String)o2);
}

}
}


}

folder.close(true);
store.close();

}
catch (MessagingException messageexception) {
messageexception.printStackTrace();
}
catch (IOException ioexception) {
ioexception.printStackTrace();
}

}

public static void main(String[] args) {
receive("mail.emailsrvr.com", "[email protected]",
"passwrd", "Status");
}
}
Ads
View Answers

February 1, 2010 at 12:41 PM


Hi Friend,

Please visit the following link:

http://www.roseindia.net/javamail/

Here you will get lot of examples related to Java Mail.

Thanks

Ads









Related Tutorials/Questions & Answers:
JavaMail flagging problems - JavaMail
JavaMail flagging problems  Hi everyone, I am working on receiving..." + mimeType); //here add the code for flagging /*if (message[i].isSet... the following link: http://www.roseindia.net/javamail/ Here you will get
Version of javamail>javamail dependency
List of Version of javamail>javamail dependency
Advertisements
arraylist problems?
arraylist problems?   myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList. After you have put all of the names into the ArrayList search through
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.*; import java.io.*; import java.util.Scanner; class Node { public boolean marked; public int node_no; public String node_type; //public float value; //public
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.*; import java.io.*; import java.util.Scanner; class Node { public boolean marked; public int node_no; public String node_type; //public float value; //public
Problems in Stringtokenizer
Problems in Stringtokenizer  hi here is my code import java.util.*; import java.io.*; import java.util.Scanner; class Node { public boolean marked; public int node_no; public String node_type; //public float value; //public
JAVAMAIL API - JavaMail
JAVAMAIL API  This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this WELCOME  
javamail in jsp - JavaMail
javamail in jsp  Hii Sir, I am working wuth a javamail programme now and i can send the mail with in the compony mail server but cant mail between other gmail , yahoo or any other mail servers. I got an exception
Problems With Struts - Development process
Problems With Struts   Respected Sir , While Deploying Struts Application in Tomcat 5.0 ,using Forward Action.This can... resolve this problems. Thanks & Regards Akhtar
JavaMail API usage - JavaMail
JavaMail API usage  Hello sir, i wrote a program to send a message from one mail account to another mail account,for that i uses JAVA and JSP two.../javamail/ Thanks. Amardeep
problems regrading .properties files
problems regrading .properties files  According to my struts application my i ve to register particular data into the DB..It will succefully registerd according to my validation condition which m placed in the validate mathod
Artifacts of javamail
List of Artifacts of javamail maven depenency
JavaMail API - JavaMail
JavaMail API  Hi My Name is Satish I have a Problem with Java Mail API when I am doing Maling programme I can able to do single mail and single CC mail but I am not able to do multiple mails How can I do this thing? Any one can
Mailing - JavaMail
Mailing  Dear Friends, How can i send mails to yahoo,gmail,other mail servers using javamail using a jsp file. Please help me
java - JavaMail
java  Hi, i want to send a mail automatically particular time for every day so, please reply me  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that that above link
java - JavaMail
java  How to send out an email using simple java  How to send out an email with attachment using simple java  Hi Friend, Please visit the following links: http://www.roseindia.net/javamail/ Thanks
forgotpassword - JavaMail
with running example. http://www.roseindia.net/javamail/ Thanks
extract content from javamail - JavaMail
extract content from javamail  Hi, I currently try the example(Read Multipart mail using Java Mail) on Javamail from the site to receive the e-mail. Then If I going to extract text the message content. What can I do
Problems connecting to a database. Java/SQLite
Problems connecting to a database. Java/SQLite  `print("try { con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite"); } catch... on an SQL database but i am having problems connecting to it, I think the problem
Java: Some problems in given condition
Java: Some problems in given condition   SIR, I want to get the values from the table( database), if any one of the column of the table value is 0. Then one alert should b printed in application using Java. If(att.getdata1()==0
Version of geronimo>javamail dependency
List of Version of geronimo>javamail dependency
start debugging problems related to the JDBC API
start debugging problems related to the JDBC API  How do I start debugging problems related to the JDBC API
Maven Dependency javamail >> 1.3.1
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.1 in your project
Maven Dependency javamail >> 1.3.2
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.2 in your project
Maven Dependency javamail >> 1.3.3
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.3 in your project
problems in parsing the xml with the special characters
problems in parsing the xml with the special characters  Hi, I have a problem, in while parsing the xml with special characters apstrophe('). I am getting the exception Caused by: javax.xml.transform.TransformerException
nsstring get value - algebra multiplication problems
nsstring get value - algebra multiplication problems  NSString Algebra multiplication problems How can i get value of X using algebra multiplication problems in nsstring? if i have two values.. 3 + 8 + X = ? Thanks
Java Mail - JavaMail
Java Mail  how to email using Java mail or automatic generated mail???  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
sending emails - JavaMail
sending emails  what is the code for sending emails in java  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks