简体   繁体   中英

How to get “Sent” folder for gmail, yahoo and for other emails using javamail?

I use JavaMail for Android. I want to get messages from "INBOX" and "SENT" folders. "INBOX" folder name the same for all email clients but "SENT" folder name specific for different clients. How can I get "SENT" folder to be insured it works for all clients.

There is an IMAP standard for this , but it's not widely implemented. Lacking that, you need to ask the user for the name of the Sent mailbox, or you need to include some heuristics that attempt to locate it by checking the names used by common mailers.

After many researches I find solution that I think should work for all mail clients. This example represent how to get sent folder via attributes.

for (Folder folder : folderList) {
            String[] attributes = ((IMAPFolder) folder).getAttributes();
            for (String attr : attributes) {
                if (attr.toLowerCase().contains("sent"))
                    return folder;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM