JavaMail flagging problems

JavaMail flagging problems

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");
}
}
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









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
JAVAMAIL API - JavaMail
JAVAMAIL API  This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this WELCOME  
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 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
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
ModuleNotFoundError: No module named 'problems'
ModuleNotFoundError: No module named 'problems'  Hi, My Python... 'problems' How to remove the ModuleNotFoundError: No module named 'problems... to install padas library. You can install problems python with following
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
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
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
What are the problems in AI?
What are the problems in AI?  Hi, I am beginner in Data Science... are the problems in AI? Try to provide me good examples or tutorials links so that I can learn the topic "What are the problems in AI?". Also tell me
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
forgotpassword - JavaMail
with running example. http://www.roseindia.net/javamail/ Thanks
Maven Repository/Dependency: javamail | javamail
Maven Repository/Dependency of Group ID javamail and Artifact ID javamail. Latest version of javamail:javamail dependencies. # Version Release Date You can read more at: Maven
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
ModuleNotFoundError: No module named 'postman_problems'
ModuleNotFoundError: No module named 'postman_problems'  Hi, My... named 'postman_problems' How to remove the ModuleNotFoundError: No module named 'postman_problems' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'practice-problems'
ModuleNotFoundError: No module named 'practice-problems'  Hi, My... named 'practice-problems' How to remove the ModuleNotFoundError: No module named 'practice-problems' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'drf-problems'
ModuleNotFoundError: No module named 'drf-problems'  Hi, My Python... 'drf-problems' How to remove the ModuleNotFoundError: No module named 'drf-problems' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'drf-problems'
ModuleNotFoundError: No module named 'drf-problems'  Hi, My Python... 'drf-problems' How to remove the ModuleNotFoundError: No module named 'drf-problems' error? Thanks   Hi, In your python
javamail
Version of geronimo>javamail dependency
List of Version of geronimo>javamail dependency
Version of javamail>mail dependency
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 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
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 Repository/Dependency: org.jvnet.mock-javamail | mock-javamail
Maven Repository/Dependency of Group ID org.jvnet.mock-javamail and Artifact ID mock-javamail. Latest version of org.jvnet.mock-javamail:mock-javamail dependencies. # Version Release Date
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
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
JavaMail and Gmail - JSP-Servlet
JavaMail and Gmail  In my previous question, I forgot to mention that following exception is arising when trapped in catch: javax.mail.MessagingException: can't determine local email address Kindly let me know
java mail - JavaMail
java mail  how to send a mail without authentication in java ?  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
ModuleNotFoundError: No module named 'solve-some-problems'
ModuleNotFoundError: No module named 'solve-some-problems'  Hi, My... named 'solve-some-problems' How to remove the ModuleNotFoundError: No module named 'solve-some-problems' error? Thanks   Hi
ModuleNotFoundError: No module named 'practice-problems-builder-ktraff'
ModuleNotFoundError: No module named 'practice-problems-builder-ktraff' ...: ModuleNotFoundError: No module named 'practice-problems-builder-ktraff' How to remove the ModuleNotFoundError: No module named 'practice-problems-builder-ktraff'
ModuleNotFoundError: No module named 'solve-some-problems'
ModuleNotFoundError: No module named 'solve-some-problems'  Hi, My... named 'solve-some-problems' How to remove the ModuleNotFoundError: No module named 'solve-some-problems' error? Thanks   Hi
ModuleNotFoundError: No module named 'jutge-problems-toolkit'
ModuleNotFoundError: No module named 'jutge-problems-toolkit'  Hi...: No module named 'jutge-problems-toolkit' How to remove the ModuleNotFoundError: No module named 'jutge-problems-toolkit' error? Thanks   Hi
Javamail - JavaMail
Javamail - JavaMail
Version of ant>ant-javamail dependency
List of Version of ant>ant-javamail dependency
gmail access using javamail API
gmail access using javamail API  how to coonect to gmail using java...://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks   .../javamail/][2] Thanks [1]: http://www.roseindia.net/javamail/ [2]: http
regarding email - JavaMail
, port: 25" is that you've incorrectly configured your properties and JavaMail... or not? If not, then something has happened to the Properties that JavaMail...://www.roseindia.net/javamail/ Thanks
mailing system in java - JavaMail
://www.roseindia.net/javamail/ Thanks

Ads