Hello All,
I am using below code to move all unread emails to another folder from inbox in outlook.
But this code was not working properly, for example if 4 emails are in unread condition it moves only 2 emails to this folder .so it was failed for remaining 2 mails .
Can u please guide to resolve the issue.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Outlook;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
// Microsoft.Office.Interop.Outlook.MailItem newEmail = null;
Microsoft.Office.Interop.Outlook.MailItem movemail = null;
Microsoft.Office.Interop.Outlook.Items items = (Microsoft.Office.Interop.Outlook.Items)myInbox.Items;
Microsoft.Office.Interop.Outlook.MAPIFolder destFolder = myInbox.Folders["Arch"];
items.Restrict("[UnRead] = true");
// Microsoft.Office.Interop.Outlook.MAPIFolder destFolder1 = mapiNameSpace.Folders["CQ Web"];
foreach (object eMail in items.Restrict("[UnRead] = true"))
{
<pre>
movemail = eMail as Microsoft.Office.Interop.Outlook.MailItem;
if (movemail != null)
{
movemail.Move(destFolder);
}
}
}
}
Regards
Arul.R
Regards,
Arul R
arul44.ece@gmail.com