时间:2021-07-01 10:21:17 帮助过:17人阅读
在已发送文件夹删除一次。
又是大哥
我是用下面的代码, 在已发送文件夹删除一次有什么代码没有?谢谢,你真好
try {
mState = NONE;
Properties props = System.getProperties();
props = System.getProperties();
if (mailType == MailType.TYPE_GMAIL) { // 如果为gmail邮箱,需要设置下两项
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "587"); // gmail smtp port 587 / 465
}
props.put("mail.smtp.host", mSmtp_host);
props.put("mail.smtp.user", mFrom_userName);
props.put("mail.smtp.password", mFrom_passWord);
props.put("mail.smtp.auth", "true");
mSession = Session.getDefaultInstance(props, null);
mSession.setDebug(false);
mMimeMsg = new MimeMessage(mSession);
mMimeMsg.setFrom(new InternetAddress(mFrom_userName));
// mMimeMsg.setContent(mContent, "text/html;charset=utf-8");
if (mToId != null)
setSendToMsg(mToId);
if (mCcId != null)
setCopyToMsg(mCcId);
if (mBccId != null)
setBCopyToMsg(mBccId);
if (mSubject != null) {
mMimeMsg.setSubject(mSubject);
}
if (mShow_name != null) {
mMimeMsg.setFrom(new InternetAddress(mShow_name + "<"
+ mFrom_userName + ">"));
}
if (mContent != null) {
setContentMp(mContent);
mMimeMsg.setContent(mp);
}
if (mFilePath != null) {
addFile(mFilePath);
}
System.out.println(mMimeMsg.getAllRecipients().toString());
Transport transport = mSession.getTransport("smtp");
System.out.println("connecting...");
mState = CONNECTING;
transport.connect(mSmtp_host, mFrom_userName, mFrom_passWord);
//
if(!transport.isConnected())
{
Log.i(Tag, "Connect failure");
return;
}
mState = CONNECTED;
Log.i(Tag, "Connected to " + mFrom_userName + " succuss");
System.out.println("sending...");
mState = SENDING;
transport.sendMessage(mMimeMsg, mMimeMsg.getAllRecipients());
mState = SENDED;
transport.close();
} catch (Exception e) {
System.out.println("failure! ");
Log.d(Tag, " failure! ", e);
e.printStackTrace();
}
先用
Folder defaultFolder = store.getDefaultFolder();
Folder[] allFolder = defaultFolder.list();
获取有什么文件夹,然后根据列表中的文件夹名getFolder
Store store= session.getStore("pop3");store.connect(host,username, password);Folder folder = store.getFolder("文件夹路径"); // 这里根据所选文件夹删除folder.open(Folder.READ_WRITE);//注意这里与读取时的区别Message message[] = folder.getMessages();BufferedReader reader = new BufferedReader ( new InputStreamReader(System.in));for(int i=0;i有两个问题
1。 Folder folder = store.getFolder("文件夹路径");
//文件夹路径里收件箱是“INBOX”,已发送是“SENDBOX”?
2。message[i].setFlag(Flags.Flag.DELETED, true);
//是局部变量, 它的变化好像没反应到邮件服务器?
多谢提供代码补允:BufferedReader reader is not used ,是不是这里要怎么用一下
有两个问题
1。 Folder folder = store.getFolder("文件夹路径");
//文件夹路径里收件箱是“INBOX”,已发送是“SENDBOX”?
2。message[i].setFlag(Flags.Flag.DELETED, true);
//是局部变量, 它的变化好像没反应到邮件服务器?
多谢提供代码
Folder defaultFolder = store.getDefaultFolder();
Folder[] allFolder = defaultFolder.list();
在这里找。
参考下: http://www.alixixi.com/program/a/2008020835375.shtml
Folder defaultFolder = store.getDefaultFolder(); 只能获得一个“INBOX”
看有个文章说POP3协议下getFolder(name)只支持“INBOX”:
getFolder
public Folder getFolder(java.lang.String name)
throws MessagingException
Only the name "INBOX" is supported.
试用了IMAP,就可以得到所有的文件夹:”INBOX, 草稿箱, 已发送, 已删除, 垃圾邮件, 广告邮件“
而我不想用IMAP,用POP3是没办法得到“已发送”邮件呢?
POP3得到?件箱?件貌似不行。
http://bbs.csdn.net/topics/10021225我在想outlook, foxmail 是怎么在不开通IMAP协议情况下实现的呢? 谢谢你了