I’m developing an addinn, that sends mails programmatically and put put them in specyfied folders depending of the mail content.
After mailitem.Move()
I get an exception “The element was moved or deleted”. It’s look like some issue with asynchronous operations and the mail hasn’t been sent yet.
Outlook.MailItem mailItem = null;
mailItem = (Outlook.MailItem)this.Application.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = Subject;
mailItem.To = To;
mailItem.Body = Body;
await Task.Run(() => mailItem.Send());
PutMailToFolder(mailItem, "Sent", "ID");
void PutMailToFolder(object Item, string DestFolder, string DestSubFolder)
{
inbox = Application.Session.Stores[ProcHubAddress].GetRootFolder();
Outlook.MAPIFolder destFolder = inbox.Folders[DestFolder].Folders[DestSubFolder];
Microsoft.Office.Interop.Outlook.MailItem mailItem = null;
mailItem = (Microsoft.Office.Interop.Outlook.MailItem)Item;
mailItem.Move(destFolder);
}