简体   繁体   中英

OUTLOOK VSTO: delete an email after sending it

I'm working with vsto for outlook. Create an email message and send it to recipient.
I want to delete the e-mail from "sent items" (or prevent its entrance there) but can not find a way to do it.
During my attempts I tried to filter emails in "sent items" by "find" and "restrict" functions on the "recipient" but I got an error of "Condition is not valid" or "Cannot parse condition. Error at "...."".

My Code is:

     MailItem reportEmail = Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);

     reportEmail.Subject = subject;
     reportEmail.To = TeamEmailAlias;
     reportEmail.Send();

How can I delete the mail from "Sent Items" now ?

thanks,

You just need to set up the DeleteAfterSubmit property of the MailItem class which allows to set a Boolean value that is True if a copy of the mail message is not saved upon being sent, and False if a copy is saved.

 MailItem reportEmail = Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
 reportEmail.DeleteAfterSubmit = true;
 reportEmail.Subject = subject;
 reportEmail.To = TeamEmailAlias;
 reportEmail.Send();

There is a MailItem.Delete() method, which should delete it from whatever folder it is in. This article on MSDN explains it, and also offers extra resources. You can also delete all items in a folder by using FolderName.Item(n).Delete() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM