Move emails to specific folder in Outlook

Hi,


I am planning to use Aspose.EMail for reading the emails from a shared mailbox, storing it to a local directory and then processed emails to a specific folder in Outlook.

What would be the best approach to do it?

Thanks,
Akshay

Hi Akshay,

Thank you for writing to us.

For downloading emails from an Exchange account that is configured with your Outlook, you can refer to the online article Save Messages from Exchange Mailbox in EML and MSG format. You can use ExchangeClient or ExchangeWebServiceClient code sample as for your needs.

Once the emails are downloaded to your local folder, you can use the following code sample to move the messages to the destination folder on the server:

Sample Code:

ExchangeWebServiceClient client = GetAsposeEWSClient1();

// Check if the destination folder exists..subfolderInfo will not be NULL if it exists
ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo();
client.FolderExists(client.MailboxInfo.RootUri, "TestFolder", out subfolderInfo);

if (subfolderInfo != null)
{
    string strMsgsFolder = "EMLS\\";
    DirectoryInfo dir = new DirectoryInfo(strMsgsFolder);

    foreach (var file in dir.GetFiles("*.eml"))
    {
        MailMessage eml = MailMessage.Load(file.Name);
        client.AppendMessage(subfolderInfo.Uri, eml);
    }
}