When you send mail using outlook, you can see that mail in sent Item folder. If you have automated your outlook mail sending process using C#, you can see all your mails in sent item folder. The sent mails remain in Sent Item folder. If you want to delete them automatically, you can do this by following the way illustrated in this article.
To automatically delete an email after sending it from Outlook using C# and Microsoft.Office.Interop, you need to set the DeleteAfterSubmit property of the MailItem object to true. Here’s a sample code snippet to demonstrate this:
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
class CFD
{
static void Main()
{
// Create an instance of Outlook application
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item
Outlook.MailItem mailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the properties of the mail item
mailItem.Subject = "Sample Mail Sending Example";
mailItem.HTMLBody = "This is a test email.";
mailItem.To = "[email protected]";
// Set DeleteAfterSubmit to true
mailItem.DeleteAfterSubmit = true;
// Send the email
mailItem.Send();
}
}
This code creates a new email, sets its subject, body, and recipient, and then sends it. The DeleteAfterSubmit property ensures that the email is deleted from the Sent Items folder after it is sent.
This will automatically remove mail from your sent item just after sending mail.