I have a piece of someone else's code that moves emails into an archive folder, but this is moving emails from and group accounts into the personal inbox of the person performing the action. I would like to update the code to use the folder in the mailbox of the selected item, but I have way of testing this currently and i'm new to C#.
The current code is as follows:
olNameSpace = outlook.GetNamespace("MAPI");
inbox = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
archive = inbox.Folders["MyArchive"];
for (int i = 1; i <= selection.Count; i++)
{
Outlook.MailItem mailItem = selection[i];
parent = mailItem.Parent;
if (parent.Name != "MyArchive")
{
mailItem.Move(archive);
}
}
Would changing this to the following fix this issue?
for (int i = 1; i <= selection.Count; i++)
{
Outlook.MailItem mailItem = selection[i];
parent = mailItem.Parent;
olNameSpace =mailItem.Session;
inbox = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
archive = inbox.Folders["MyArchive"];
if (parent.Name != "MyArchive")
{
mailItem.Move(archive);
}
}
I've remove the check for folder existing and another action that's performed, as they are irrelevant for this question. Thank you