This tutorial is about manipulating message threads using Aspose.Email Cloud build-in client.
You may ask ‘Is there any difference between messages and threads?’. At first glance, the difference is not obvious, but there is.
Messages. The most important entity when you create an email application. The message contains email’s body, attachments, sender, recipients, metadata and other useful pieces of information.
Threads. Messages, collected together with a variety of parameters are called threads. Using threads, you can get more structured emails in the mailbox.
Using threads, you can easily structure emails in the mailbox. Instead of working with an unstructured list of messages, it is better to work and analyze only certain threads of emails. In the picture below you can see how the messages are arranged in threads:
Exchange Web Services (EWS)Accounts: native support, no extra configuration needed. Exchange Web Services is an alternative to the MAPI protocol. EWS is used by the latest version of Microsoft Outlook for Mac and Microsoft Entourage for Mac.
POP3: thread support is implemented using message cache. Message cache location on storage should be specified. The Post Office Protocol allows manipulating the user’s client application with a mailbox supported on a mail server.
IMAP: thread support is implemented using message cache, at the moment. Native threads support will be implemented in a future version. The Internet Message Access Protocol is the Internet protocol that allows an email client to access emails on a remote mail server.
WebDav: threads are not supported.
Virtual Multi-account: gets threads from underlying accounts and provides them as is.
Thread Support using Message Cache
Aspose.Email Cloud built-in email client supports native threads for EWS and IMAP accounts. For POP3 accounts we provide this functionality using our own threads implementation. This implementation uses messages’ cache, located on Aspose Storage and our own threads algorithm, which generates threads based on message subject and participants.
Message cache is also used for IMAP accounts if the IMAP server does not provide native threads.
To support threads using cache, you should provide cache location during email account setup:
Setup account with cache file
The account.cache file contains basic information about messages and threads (folder, subject, message identifiers, dates and participants).
GetList caches only messages for folders that were requested. So, to initialize cache for several folders, you should call GetList for every single folder. Folder cache initialization takes more time than updating cache in the future.
GetList is the only way to sync messages with the account. It finds all messages that were not cached before, and adds them to the existing threads or creates new ones. GetList also removes messages from the cache if they were removed from the account.
GetList, Delete, Move methods lock account.cache file while processing. So, these methods will never run in parallel.
Delete and Move methods delete/move messages in the email account and also update information about affected messages in account.cache file.
GetMessages method does not update and lock account.cache file, this method returns only messages that exist in the cache.
Get List of Threads
To get the list of threads for a given folder (folder parameter is ignored for POP3 accounts), use GetList method from ClientThreadApi:
Set parameter updateFolderCache to false if you don’t need to sync threads cache with your email account.
Fetch Thread Messages
GetList method returns all email threads from the folder. All threads contain a lists of messages. However, these messages contain only basic information: MessageId, Date, Subject, Participants (From, To, CC). Use GetMessages method from ClientThreadApi if you need to fetch full messages for a thread, including message bodies, attachments, alternate views, etc.
Some native thread implementations (such as EWS conversations) require folder argument. However, you can set this parameter to null if cached threads used (the thread’s folder is already stored in the cache).
Some native thread implementations (such as EWS conversations) require folder argument. However, you can set this parameter to null if cached threads used (the thread’s folder is already stored in the cache).
Mark thread as read
Delete Thread
You can delete the thread and all corresponding messages using Delete method from ClientThreadApi.
Some native thread implementations (such as EWS conversations) require folder argument. However, you can set this parameter to null if cached threads used (the thread’s folder is already stored in the cache).
Move Thread to Another Folder
All thread messages can be moved from one folder to another using one single request of Move method from ClientThreadApi (POP3 is not supported):