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.

CopyC#
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.

CopyC#
// 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

  ClassDescription
Public classMailAttachmentDownloaderPlatform
The MailAttachmentDownloader main platform class. Provides access to an instance of the IProcessMail interface.

Interfaces

  InterfaceDescription
Public interfaceIDownloadStats
Provides some download statistics of successful and failed attachment downloads.
Public interfaceIFolder
Provides a folder data structure to provide access to folders within a mail account.
Public interfaceIMailSearchSettings
Mail search settings interface. This can be used to set various search preferences before downloading attachments via StartDownloadingAttachments()()()().
Public interfaceIProcessMail
The main interface that provides functionality to download attachments.
Public interfaceIProcessMailEvent
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.
Public interfaceIProcessSearchResultEvent
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

  DelegateDescription
Public delegateStatusUpdate
Delegate function that is used when events are raised by the platform when StartDownloadingAttachments()()()() or StartListFolders()()()() are called.

Enumerations

  EnumerationDescription
Public enumerationDownloadFileType
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.
Public enumerationFields
List of fields to use in FilenameOrdering.
Public enumerationMailSearchHeaderType
Use this to select the attachments that needs to be downloaded based on the message headers, set using MailSearchHeaderSettings
Public enumerationProcessMailEventType
Definition for various different EventType's. See description for each event for more detail on when these are generated.

See Also