Received mail cannot move to another folder...especailly HOTMAIL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

actually, I am doing a AddIn.. I wish to move all the new recieved mails
into my own folder, which named "TEMP FOLDER". However, when I click
"Send/Receive", Some mails can , but some are not..
In addition, sometimes after "Click/Receive" Event finished, but my program
did not executed... The following are my codes, I wish to compare all the new
arrived mails with my recorded mail information in my program:

private Microsoft.Office.Interop.Outlook.MailItem tempItem;
private Microsoft.Office.Interop.Outlook.MAPIFolder tempFolder;
private Microsoft.Office.Interop.Outlook.Items temp_Items;

public void OnStartupComplete(ref System.Array custom)
{
MAPIFolder baseFolder =
outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
tempFolder = baseFolder.Folders.Add("Temp Folder",
OlDefaultFolders.olFolderInbox);

temp_Items = tempFolder.Items;
temp_Items.ItemAdd+=new
ItemsEvents_ItemAddEventHandler(temp_Items_ItemAdd);

this.checkAllInbox();
}

private void checkAllInbox()
{
Folders folders = outlookNS.Folders;
for(int i = 1; i <= folders.Count; i++)
{
MAPIFolder folder = folders;
Folders fixedFolders = folder.Folders;

//get every folder of each account
for(int j = 1; j <= fixedFolders.Count; j++)
{
MAPIFolder fixedFolder = fixedFolders[j];
// get Inbox folder

if(fixedFolder.Name.Equals("Inbox"))
{
inboxFolder = fixedFolder;

inbox_Items = inboxFolder.Items;
inbox_Items.ItemAdd+=new
ItemsEvents_ItemAddEventHandler(inbox_Items_ItemAdd);

}
}
}
}


private void inbox_Items_ItemAdd(object Item)
{
Microsoft.Office.Interop.Outlook.MailItem mailItem =
(Microsoft.Office.Interop.Outlook.MailItem) Item;
Microsoft.Office.Interop.Outlook.MailItem copyItem =
(Microsoft.Office.Interop.Outlook.MailItem) mailItem.Copy();
tempItem = (Microsoft.Office.Interop.Outlook.MailItem)
copyItem.Move(this.tempFolder);
}

private void temp_Items_ItemAdd(object Item)
{
Microsoft.Office.Interop.Outlook.MailItem mailItem =
(Microsoft.Office.Interop.Outlook.MailItem) Item;
}
 
Hello Robin,

from my knowledge:
1. the ItemAdd Event doesn't come when more then 16 Items are added to
Folder

Maybe you could try the following: (Just an Idea)
After a Send/Receive End or Error Event (You must register to the events)
(See Example: http://www.outlookcode.com/codedetail.aspx?id=786)
do a restrict in your Inbox Folders for Mail received after last sync.
Remember all that Emails in your Application.
Remember last sync time.

Another Issue:
The Items also could be of another Type, not only Emails, so check the Item
first, before you cast.

Also: You have no Try / Catch statement, so your AddIn could crash.

Greets, Helmut Obertanner
 
Back
Top