Move All Unread Emails to other folder from outlook inbox using c#

Posted by Arul44ece under C# on 4/2/2015 | Points: 10 | Views : 1749 | Status : [Member] | Replies : 2
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



Responses

Posted by: Rajnilari2015 on: 4/3/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Please go thru these article

a) http://dotnetvisio.blogspot.in/2013/07/outlook-addins-c-to-move-outlook-inbox.html

b) http://stackoverflow.com/questions/28020953/move-email-to-another-folder-with-openpop

This will definitely help you.

--
Thanks & Regards,
RNA Team

Arul44ece, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arul44ece on: 4/3/2015 [Member] Starter | Points: 25

Up
0
Down
Hi rajni,

i am also done same thing like u mentioned above examples .

It working partially ,that is the problem. If 6 mails are unread then it moves only 3 mails to unread folder.

Remaining still in inbox only

Regards
Arul



Regards,

Arul R
arul44.ece@gmail.com

Arul44ece, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response