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", "vidya_n@xyz.net",
"passwrd", "Status");
}
}
View Answers
February 1, 2010 at 12:41 PM
Related Tutorials/Questions & Answers:
JavaMail flagging problems - JavaMailJavaMail 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
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 - JavaMailJAVAMAIL API This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this
WELCOME
Problems in StringtokenizerProblems 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 StringtokenizerProblems 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 StringtokenizerProblems 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 - JavaMailjavamail 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 - JavaMailJavaMail 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
JavaMail API - JavaMailJavaMail 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 - JavaMailMailing Dear Friends,
How can i send mails to yahoo,gmail,other mail servers using
javamail using a jsp file.
Please help me
java - JavaMailjava 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 - JavaMailjava 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 filesproblems 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
extract content from javamail - JavaMailextract 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/SQLiteProblems 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 conditionJava: 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
Java Mail - JavaMailJava 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 - JavaMailsending 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-ServletJavaMail 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 - JavaMailjava 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
gmail access using javamail APIgmail 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