Example of how to delete a message from mail server
Source: Internet
Author: User
Question How does you delete a message from the mail server?
Derived from a unanswered question originally posed by Benjamin Alejandro Rodriguez Rengifo
Topics Java:API:JavaMail:IMAP4, Java:API:JavaMail:POP3
Author John Zukowski
Created 23-feb-00 Modified 25-jul-00
Answer
The basic process of deleting a message is to call Setflag () on the and set the Flags.Flag.DELETED Flag to True.
Message.setflag (Flags.Flag.DELETED, true);
Then, when you close the folder, deleted messages'll be removed.
Be sure to open the folder for Read/write access:
Folder.open (Folder.read_write);
The following program demonstrates listing the "all" and prompting for deletion:
Import java.io.*;
Import javax.mail.*;
Import javax.mail.internet.*;
public class Deletemessageexample {
public static void Main (String args[]) throws Exception {
String host = Args[0];
String username = args[1];
String password = args[2];
Get sessions
Session session = Session.getinstance (
System.getproperties (), NULL);
Get the Store
Store store = Session.getstore ("POP3");
Store.connect (host, username, password);
Get folder
Folder folder = Store.getfolder ("INBOX");
Folder.open (Folder.read_write);
BufferedReader reader = new BufferedReader (
New InputStreamReader (system.in));
Get directory
Message message[] = Folder.getmessages ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.