Can I delete the emails sent using Javamail?

Source: Internet
Author: User
Can I delete the emails sent using Javamail? Eldest brother, I used Javamail to send emails. do not display the emails that can be sent in the sent folder?

Can I delete emails that have been sent out ?. Thank you.


Reply to discussion (solution)

Delete it once in the sent folder.

Big Brother again
I used the following code to delete a folder that has been sent. Is there any code? Thank you!
Try {
MState = NONE;
Properties props = System. getProperties ();
Props = System. getProperties ();
If (mailType = MailType. TYPE_GMAIL) {// if it is a gmail mailbox, you need to set the following two items
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 ();
}

First use
Folder defaultFolder = store. getDefaultFolder ();
Folder [] allFolder = defaultFolder. list ();
Obtain the folder, and then getFolder according to the folder name in the list.

Store store = session. getStore ("pop3"); store. connect (host, username, password); Folder folder = store. getFolder ("folder path"); // Here, the folder is deleted based on the selected folder. open (Folder. READ_WRITE); // note the difference between this parameter and read: Message [] = folder. getMessages (); BufferedReader reader = new BufferedReader (new InputStreamReader (System. in); for (int I = 0; I
  
  

There are two problems
1. Folder folder = store. getFolder ("Folder path ");
// In the folder path, the INBOX is "INBOX" and the sent is "SENDBOX "?
2. Message [I]. setFlag (Flags. Flag. DELETED, true );
// Is a local variable. does it seem to have changed to the email server?

Thanks for providing code

Supplement: BufferedReader is not used. how can I use it here?

There are two problems
1. Folder folder = store. getFolder ("Folder path ");
// In the folder path, the INBOX is "INBOX" and the sent is "SENDBOX "?
2. Message [I]. setFlag (Flags. Flag. DELETED, true );
// Is a local variable. does it seem to have changed to the email server?

Thanks for providing code



Folder defaultFolder = store. getDefaultFolder ();
Folder [] allFolder = defaultFolder. list ();

Here.

Reference: http://www.alixixi.com/program/a/2008020835375.shtml


Folder defaultFolder = store. getDefaultFolder (); only one "INBOX" can be obtained"

I have read an article saying that getFolder (name) under POP3 only supports "INBOX ":
GetFolder
Public Folder getFolder (java. lang. String name)
Throws MessagingException
Only the name "INBOX" is supported.

After using IMAP, you can get all the folders: "INBOX, draft box, sent, deleted, spam, and Ad mail".
I don't want to use IMAP, but can't I get a "sent" email with POP3?

POP3 get? Case? Does not seem to work.
Http://bbs.csdn.net/topics/10021225

I was wondering how outlook and foxmail were implemented without activating the IMAP protocol? Thank you.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.