none
How to automatically permanently delete a sent email that contains specified text strings in the Sent folder RRS feed

  • Question

  • I originally posted the question at the Outlook IT Pro Discussions forum, and Steve Fan suggested me to post the question here. Here is my original question:

    "Our mobile employees use their iPhone to scan documents and then email to their Outlook accounts. As a result, the scanned documents will end up in both their Inbox and Sent folders, which will take up their mailbox space very fast. Is there a way to configure outlook to automatically permanently delete an email that contains specified text strings (in its subject and body) in the Sent folder? Anybody knows? We use Outlook 2010. Thank you for any kind response!"

    Steve provided the sample code for a macro that will set the message to expire in 1 or half day (the following is the sample code), but ideally I'd like the deletion to be happened instantly (i.e., the minute that it goes into the Sent folder, it will get deleted).

    Steve's sample code:

    Sub SetExpire(Item As Outlook.MailItem)
     
    If Left(LCase(Item.Subject), 7) = "weather" Then
        Item.ExpiryTime = Now + 1
        Item.Save
    End If
     
    End Sub

    Any feedback will be greatly appreciated!

    Wednesday, July 29, 2015 6:56 PM

Answers

  • Hello,

    The MailItem class provides the DeleteAfterSubmit property which allows to set up 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.

    • Marked as answer by L.HlModerator Wednesday, August 5, 2015 9:02 AM
    Wednesday, July 29, 2015 8:09 PM
  • Hi,

    >>I'd like the deletion to be happened instantly

    you may delete the file when mail item is received, and you may follow the below link to delete the mailItem

    How to: Programmatically Perform Actions When an E-Mail Message Is Received

    Hope this could help you.

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by L.HlModerator Wednesday, August 5, 2015 9:02 AM
    Thursday, July 30, 2015 2:39 AM
    Moderator

All replies

  • Hello,

    The MailItem class provides the DeleteAfterSubmit property which allows to set up 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.

    • Marked as answer by L.HlModerator Wednesday, August 5, 2015 9:02 AM
    Wednesday, July 29, 2015 8:09 PM
  • Hi,

    >>I'd like the deletion to be happened instantly

    you may delete the file when mail item is received, and you may follow the below link to delete the mailItem

    How to: Programmatically Perform Actions When an E-Mail Message Is Received

    Hope this could help you.

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by L.HlModerator Wednesday, August 5, 2015 9:02 AM
    Thursday, July 30, 2015 2:39 AM
    Moderator
  • If instead of creating a new Mail item (with attachment) and sending it to themselves the users created a Post item(with attachment) that would be posted directly to the user inbox then the desired content would be available without a duplicate in the sent items folder.

    Of course it might be easier to create a programmatic solution compared to changing user behavior :).

    Thursday, July 30, 2015 10:54 AM
  • Thank you Lan!

    Does the following code move the item to the Junk Emails folder?

    mail.Move(outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook. OlDefaultFolders.olFolderJunk));

    If I'd like to permanently delete the item instead of moving it to the Deleted Items or Junk Emails folder, how to modify the code?

    Thank you!

    Thursday, July 30, 2015 12:54 PM
  • Thanks for your reply!

    I'd first try to look for a solution that will require no action from the users because many of our users are not that technology savvy. But if a programmatic solution doesn't work, then I'll look into this alternative.

    Thanks!

    Thursday, July 30, 2015 1:04 PM
  • Thank you Lan!

    Does the following code move the item to the Junk Emails folder?

    mail.Move(outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook. OlDefaultFolders.olFolderJunk));

    If I'd like to permanently delete the item instead of moving it to the Deleted Items or Junk Emails folder, how to modify the code?

    Thank you!

    Oh...I think Eugene has provided a way to do it (the DeleteAfterSubmit property)...silly me :) 
    Thursday, July 30, 2015 1:14 PM