Create Folder and Manage Folder using IMAP4/Exchange Web Service (EWS)/WebDAV in C++/CLI/CLR

In previous section, I introduced how to parse non-delivery report (NDR) in C++/CLI/CLR. In this section, I will introduce how to create folders and manage folders with IMAP4/Exchange Web Service (EWS)/WebDAV protocol in C++/CLI/CLR.

Create Folder and Delete Folder

Because IMAP4/Exchange Web Service (EWS)/WebDAV protocol supports folder access, so we can retrieve email from other mailbox rather than default “INBOX”, I have introduced it in other sections. In this section, I will introduce how to use EAGetMail to create folder and delete folder with IMAP4/Exchange Web Service/WebDAV protocol. Notice: POP3 protocol doesn’t support this feature.

[C++/CLI/CLR Example - Create Folder and Delete Folder]

The following example codes demonstrate how to create folder and delete folder.


To get the full sample projects, please refer to Samples section.

#include "stdafx.h"

using namespace System;
using namespace System::IO;
using namespace EAGetMail; //add EAGetMail namespace

int main(array<System::String ^> ^args)
    //To create folder with Exchange Web Service, please change
    //ServerProtocol::Imap4 to ServerProtocol::ExchangeEWS to MailServer constructor
    // and also set oServer->SSLConnection to true

    //To create folder with Exchange WebDAV, please change
    //ServerProtocol::Imap4 to ServerProtocol::ExchangeWebDAV to MailServer constructor

    //Exchange Server supports IMAP4 protocol as well, but in Exchange 2007
    //or later version, IMAP4 service is disabled by default. If you don't want to use IMAP4
    //to manage folder from Exchange Server, you can use Exchange Web Service (Exchange 2007/2010 or
    //later version) or WebDAV (Exchange 2000/2003) protocol.

    // For Exchange Web Service/WebDAV protocol, please ignore port property
    // and use domain\user as the user name.

    MailServer ^oServer = gcnew MailServer("",
        "", "testpassword", ServerProtocol::Imap4 );
    MailClient ^oClient = gcnew MailClient("TryIt");

    // Set IMAP4 server port
    oServer->Port = 143;

    // If your IMAP4 server requires SSL connection,
    // Please add the following codes:
    // oServer->SSLConnection = true;
    // oServer->Port = 993;

        Imap4Folder ^folder = oClient->CreateFolder( NULL, "TestFolder" );

        array<Imap4Folder^>^folders = oClient->Imap4Folders;
        int count = folders->Length;
        for( int i = 0; i < count; i++ )
            Imap4Folder ^fd = folders[i];
            Console::WriteLine( "folder: {0}", fd->FullPath );

        oClient->DeleteFolder( folder );

    catch (Exception ^ep)

    return 0;

Retrieve/Copy/Move/Upload Email to Folder

To retrieve emails from a specified folder, please use SelectFolder method; To move email from a folder to another folder, please use Move method; To copy email from a folder to another folder, please use Copy method; To upload an email file from local disk to server folder, please use Append method.

Access Exchange Shared Mailbox

A MS Exchange shared mailbox is a mailbox that multiple users can use to read and send email messages. To access shared mailbox, please use MailServer.Alias property.

Access Exchange 2007/2010/2013/2016 Public Mailbox

Since Exchange 2007 or later version (2010/203), IMAP4 protocol does not expose public folders to mail client. If you want to access public folders on MS Exchange 2007/2010/2013/2016 or later version, please use MailClient.QueryEWSPublicFolders method.

Next Section

Total sample projects in EAGetMail Mail Component installation package.



If you have any comments or questions about above example codes, please click here to add your comments.