Mail Attachment Downloader API provides you with a unique set of powerful APIs to automate your mail attachment downloading needs from both IMAP or POP3 mail servers.
The MailAttachmentDownloaderPlatform class provides access to the IProcessMail interface in which the StartDownloadingAttachments()()()() method can be invoked to start downloading attachments based on search criteria you specify in IMailSearchSettings. As mail items get downloaded, you can monitor the progress by processing events defined in IProcessMailEvent.
Example code is shown below of a sample application.
try { // Intialize the platform with the mail server information, where m_secureStringPassword contains the password m_platformInstance = new MailAttachmentDownloaderPlatform("imap.gmail.com", (ushort)993, "gear@gmail.com", m_secureStringPassword, true, true, true); // Get the processmail interface instance and store in local member data. m_procMail = m_platformInstance.GetProcessMail(); // Register event handler m_procMail.StatusUpdateInstance += new StatusUpdate(this.StatusUpdate); ...... // Get the search settings. IMailSearchSettings searchSettings = (IMailSearchSettings)m_procMail.GetSearchSettings(); // Download documents searchSettings.DownloadFilesOfType = DownloadFileType.Documents; // Save files in the current directory. searchSettings.SaveAttachmentsInDirectory = Directory.GetCurrentDirectory(); // Set the max connections to 1. searchSettings.MaxConnections = 1; // Download the attachments based on search settings set above. m_procMail.StartDownloadingAttachments(); } catch (Exception e) { Console.WriteLine(e.Message); }
And StatusUpdate above is defined below.
// As events arrive, write them out in the command line. public void StatusUpdate(IProcessMailEvent imapEvent) { switch (imapEvent.EventType) { case ProcessMailEventType.MailProcessSearchResults: IProcessSearchResultEvent processEvent = (IProcessSearchResultEvent)imapEvent; Console.WriteLine("Processing message " + processEvent.MessageNumberBeingProcessed + " of " + processEvent.TotalNumberOfMessages + "...."); break; case ProcessMailEventType.MailDownloadComplete: Console.WriteLine(imapEvent.StatusString + ", file=" + Path.GetFileName(imapEvent.FilenameOrFoldername)); break; default: Console.WriteLine(imapEvent.StatusString); break; } }
Classes
| Class | Description | |
|---|---|---|
| MailAttachmentDownloaderPlatform |
The MailAttachmentDownloader main platform class. Provides access to an instance of the IProcessMail interface.
|
Interfaces
| Interface | Description | |
|---|---|---|
| IDownloadStats |
Provides some download statistics of successful and failed attachment downloads.
| |
| IFolder |
Provides a folder data structure to provide access to folders within a mail account.
| |
| IMailSearchSettings |
Mail search settings interface. This can be used to set various search preferences before downloading attachments via StartDownloadingAttachments()()()().
| |
| IProcessMail |
The main interface that provides functionality to download attachments.
| |
| IProcessMailEvent |
This interface provides parameters associated with an event that is generated by the platform. These events indicate where the platform is in the process when one of StartDownloadingAttachments()()()() or StartListFolders()()()() are called.
| |
| IProcessSearchResultEvent |
When the EventType is MailProcessSearchResults, the following event is raised.
You can use the data contained within to determine the message that is currently being processed and the total number of messages that needs to be processed (including the ones that have already been processed).
|
Delegates
| Delegate | Description | |
|---|---|---|
| StatusUpdate |
Delegate function that is used when events are raised by the platform when StartDownloadingAttachments()()()() or StartListFolders()()()() are called.
|
Enumerations
| Enumeration | Description | |
|---|---|---|
| DownloadFileType |
Use this to selectively download only certain file types, set using DownloadFilesOfType and DownloadFilesOfTypeOtherList.
This can be used as a bitmask with more than one selected.
| |
| Fields |
List of fields to use in FilenameOrdering.
| |
| MailSearchHeaderType |
Use this to select the attachments that needs to be downloaded based on the message headers, set using MailSearchHeaderSettings | |
| ProcessMailEventType |
Definition for various different EventType's. See description for
each event for more detail on when these are generated.
|