最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何从mail server删除一条消息的例子
时间:2022-07-02 18:10:20 编辑:袖梨 来源:一聚教程网
Question How do you delete a message from the mail server?
Derived from An 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 message and set the Flags.Flag.DELETED flag to true.
message.setFlag(Flags.Flag.DELETED, true);
Then, when you close the folder, deleted messages will be removed.
Be sure to open the folder for read/write access:
folder.open(Folder.READ_WRITE);
The following program demonstrates listing each message in the folder 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 session
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();
Derived from An 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 message and set the Flags.Flag.DELETED flag to true.
message.setFlag(Flags.Flag.DELETED, true);
Then, when you close the folder, deleted messages will be removed.
Be sure to open the folder for read/write access:
folder.open(Folder.READ_WRITE);
The following program demonstrates listing each message in the folder 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 session
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();
相关文章
- 华夏绘世录平民火队怎么搭配 平民火队配队攻略 09-17
- 逆战未来怎么快速刷金币-逆战未来金币快速获取方法介绍 09-17
- 猎风传说武器升级怎么升级-猎风传说武器升级升级玩法分享 09-17
- 无主之地4通关后快速刷经验方法 怎么快速升级 09-17
- 阴阳师妙主九命猫御魂怎么搭配-SP妙主九命猫御魂搭配推荐 09-17
- 为了吾王僧侣怎么获取 09-17