Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a requirement to create dynamic Email and send to respective user. After sending, that email need to be move the sent email to some custom folder. When moving giving error "System.Runtime.InteropServices.COMException: 'The item has been moved or deleted.'"

What I have tried:

var inbox = outlookFormRegion.Application.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
MAPIFolder moveToFolder = inbox.Folders["Custom Tickets"];

var app = new Microsoft.Office.Interop.Outlook.Application();
MailItem forwardMailItem = app.CreateItem(OlItemType.olMailItem);
forwardMailItem.Subject = "Ticket: 11254875";
forwardMailItem.Body = "Testing";
forwardMailItem.Send();
forwardMailItem.Move(moveToFolder);
Posted
Updated 17-Mar-20 4:25am
Comments
Richard Deeming 17-Mar-20 10:35am    
Why are you creating a new application instance? I suspect you should replace:
var app = new Microsoft.Office.Interop.Outlook.Application();

with:
var app = outlookFormRegion.Application;

1 solution

I'd suggest to create a rule to move sended item to the specific folder: Move Sent Emails to a Specific Folder Automatically[^]

Another solution is to search for specific item in MAPI folder (Send Items), then to move it.
MailItem.Move method (Outlook) | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 9224291 17-Mar-20 10:26am    
Thanks for your quick reply. But, issue is that mails are moved to folders based on some conditions and it needs to be handled in C# as there are lots of users who are going to use it.
Maciej Los 17-Mar-20 10:31am    
So, you need to develop second part of solution...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900