Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 请问,用Javamail发送的邮件能不能删除掉?

请问,用Javamail发送的邮件能不能删除掉?

Jun 23, 2016 pm 01:55 PM
javamail send

大哥, 我用Javamail实现了发送邮件, 能不能发送出去的邮件不要显示在已发送文件夹呢?

能删除掉已发送出去的邮件吗?.  谢谢了


回复讨论(解决方案)

在已发送文件夹删除一次。

又是大哥
我是用下面的代码, 在已发送文件夹删除一次有什么代码没有?谢谢,你真好
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<message.length;i++){	message[i].setFlag(Flags.Flag.DELETED, true);//我这里是删除了所有的文件,可根据需要来编写代码}folder.close(true);//注意这里与读取的区别,这里是确认删除的操作....store.close();
Copy after login

有两个问题
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协议情况下实现的呢? 谢谢你了

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

WhatsApp Tips: How to Send HD Photos and Videos WhatsApp Tips: How to Send HD Photos and Videos Sep 10, 2023 am 10:13 AM

WhatsApp has launched a new option that allows users to send photos and videos in high resolution through the messaging platform. Read on to find out how it's done. WhatsApp has released an update that allows iPhone and Android users to send photos and videos in high resolution, finally addressing the service's low-quality media sharing limitations. The option is called "HD Quality" and means users can send clearer photos and videos with minimal compression. For example, images captured on the iPhone can now be sent at 3024x4032 resolution instead of the previous maximum of 920x1280, while videos can be sent at 1280×718 resolution instead of 848×476.

How to send files to others on TikTok? How to delete files sent to others? How to send files to others on TikTok? How to delete files sent to others? Mar 22, 2024 am 08:30 AM

On Douyin, users can not only share their life details and talents, but also interact with other users. In this process, sometimes we need to send files to other users, such as pictures, videos, etc. So, how to send files to others on Douyin? 1. How to send files to others on Douyin? 1. Open Douyin and enter the chat interface where you want to send files. 2. Click the &quot;+&quot; sign in the chat interface and select &quot;File&quot;. 3. In the file options, you can choose to send pictures, videos, audio and other files. After selecting the file you want to send, click &quot;Send&quot;. 4. Wait for the other party to accept your file. Once the other party accepts it, the file will be transferred successfully. 2. How to delete files sent to others on Douyin? 1. Open Douyin and enter the text you sent.

How to get HTML form data as text and send to html2pdf? How to get HTML form data as text and send to html2pdf? Sep 06, 2023 pm 12:21 PM

html2pdf is a JavaScript package that allows developers to convert html to canvas, pdf, images, and more. It takes html as parameter and adds it to pdf or desired document. Additionally, it allows users to download the document after adding html content. Here we will access the form and add it to the pdf using the html2pdfnpm package. We will see different examples to add form data to pdf. Syntax User can follow the following syntax to pass html form data as text and send it to html2pdf. varelement=document.getElementById('form');html2

Compare and recommend Java email sending libraries: find the right email sending tool for you Compare and recommend Java email sending libraries: find the right email sending tool for you Dec 27, 2023 am 08:38 AM

Recommendation and comparison of Java email sending libraries: Choose the email sending tool that suits you, you need specific code examples Summary: When developing Java applications, we often need to send emails. This article will introduce several commonly used Java email sending libraries and compare them to help you choose the email sending tool suitable for your project. In addition, this article will provide specific code examples so that readers can better understand how to use these libraries. 1. JavaMailAPIJavaMailAPI is a Java platform

PHP email parsing and sending functions: email parsing and sending skills for imap_open, imap_search, mail and other functions PHP email parsing and sending functions: email parsing and sending skills for imap_open, imap_search, mail and other functions Nov 18, 2023 pm 12:23 PM

In-depth explanation of PHP email parsing and sending functions: Email parsing and sending skills of imap_open, imap_search, mail and other functions, which require specific code examples. Introduction: With the popularity of email, using PHP to parse and send emails has become a common requirement in network development. . This article will introduce in detail several commonly used email parsing and sending functions in PHP: imap_open, imap_search and mail. By understanding the usage techniques and specific code examples of these functions, readers can

How to use check-ins with home, different locations, and timers How to use check-ins with home, different locations, and timers Mar 24, 2024 am 09:31 AM

How to let others know that you have arrived at your destination. Telling others that you have arrived at your destination safely is the most common way of &quot;checking in&quot; and it is easy to operate. Here are the steps to set up before you’re ready to embark on the next leg of your journey. Open a message and start a conversation with the person you want to send a check-in to. Click the plus (+) icon next to the message field. Click Check-in. Click Edit at the bottom of the prompt. Enter the destination you want to go to. Select &quot;Done&quot; in the upper right corner and send &quot;Check-in.&quot; &quot;When entering your destination, you can choose different modes of travel depending on your needs, whether that's by car, public transport or walking. Make sure you choose the device you're using correctly so your device can accurately estimate how long it will take to get to your destination. This allows you to better plan your trip and get you to your destination more conveniently.

PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails PHP Mail Usage Guide: Simple and easy-to-understand tutorial for sending emails Mar 28, 2024 pm 12:12 PM

PHP is a scripting language widely used for developing web applications. It provides many functions for handling email sending. This article will introduce you to how to use the email sending function in PHP and provide specific code examples. 1. Preparation Before using PHP to send emails, you first need to ensure that your server has been configured to send emails. Generally speaking, you need an SMTP server to send emails. You can use the SMTP server provided by your email provider, such as Gmail's SMTP

Email sending and receiving -- integrating email functions in web applications Email sending and receiving -- integrating email functions in web applications Sep 12, 2023 pm 06:12 PM

Sending and receiving emails - Integrating email functions in web applications With the popularity of the Internet, email has become an indispensable part of people's lives and work. With the development of Web applications, integrating email functions into Web applications has become an increasingly popular requirement. This article will introduce how to implement the sending and receiving functions of emails in web applications. Part 1: Integration of the email sending function To implement the email sending function, you need to consider the following steps: To set up the email server to send emails in a web application, you first need to

See all articles