JavaMail

A

alex.korsak

I didn't find some information: how can i remove message from mail.
source:

Properties properties = System.getProperties();

Session session = Session.getInstance(properties, null);
try {
Store store = session.getStore("imap");
store.connect("imap.mail.ru","*******","******");
Folder inbox = store.getDefaultFolder();
inbox = inbox.getFolder("INBOX");

inbox.open(Folder.READ_WRITE);
int count = inbox.getMessageCount();
System.out.println("Number of mails is " + count);
for (int i = 1; i <= count; i++) {
Message message = inbox.getMessage(i);
String subject = message.getSubject();
if (subject.toLowerCase().indexOf("c++") != -1) {
System.out.println(message.getSubject());
// there remove message
} // end if
} // end for

inbox.close(true);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} // end try
 
J

Juan Singh

Refer to Folder.setFlag() method. You have to set the flag of all
desired messages to DELETED.
 
E

Eric Sosman

I didn't find some information: how can i remove message from mail.
source:
[... snipped; see up-thread ...]

Call

message.setFlag(Flag.DELETED, true);

.... to mark a message for deletion. All the marked
messages will be deleted later, when you call

inbox.close(true);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top