How to Auto Remove the Attachments of an Email after Sending It in Outlook

If you’re accustomed to removing the attachments of emails after you sending them out, you can use the method introduced in this article, which is using Outlook VBA to help you auto get it.

As the attachments of the outgoing emails are usually stored in your own PC, you may be used to deleting the attachments after you send out the emails. This will keep your PST file in small size, which can not only ensure good performance of your Outlook but also reduce the odds of PST corruption. Therefore, if you would like to let Outlook automatically delete the attachments of outgoing emails, you can use the following method, which is applying VBA codes.

Auto Remove the Attachments of an Email after Sending It

Auto Remove the Attachments of an Email after Sending It

  1. At the very outset, launch your Outlook application.
  2. Then press “Alt + F11” key shortcuts.
  3. Next you will get into the Outlook VBA editor.
  4. Subsequently, you should open the “ThisOutlookSession” project window.
  5. Then copy and paste the following VBA codes into it.
Public WithEvents objSentMails As Outlook.Items

Private Sub Application_Startup()
    Set objSentMails = Outlook.Application.Session.GetDefaultFolder(olFolderSentMail).Items
End Sub

Private Sub objSentMails_ItemAdd(ByVal Item As Object)
    Dim objSentMail As Outlook.MailItem
    Dim objAttachments As Outlook.attachments
    Dim i As Long
    Dim strAttachmentInfo As String
 
    'Only work on emails
    If Item.Class = olMail Then
       Set objSentMail = Item
    End If
 
    Set objAttachments = objSentMail.attachments
 
    While objAttachments.Count > 0
          'Get the information of removed attachments
          strAttachmentInfo = "<HTML><BODY>Attachment Removed: " & objAttachments.Item(1).DisplayName & "</HTML></BODY>---------------------------------------------------------" & strAttachmentInfo
          objAttachments.Item(1).Delete
    Wend
 
    'Insert the information of removed attachments to the body
    objSentMail.HTMLBody = strAttachmentInfo & objSentMail.HTMLBody
    objSentMail.Save
End Sub

VBA Codes - Auto Remove the Attachments of an Email after Sending It

  1. After that, you ought to sign this code.
  • Firstly, use Digital Certificates for VBA Projects to create a certificate.
  • Then assign this certificate to the new macro. Click “Tools” > “Signature” and then just follow the onscreen instructions.
  1. Later you can back to main Outlook window and hit “Macro Security” under “Developer” tab.
  2. Next in the popup dialog box, change macro settings to permit the digitally signed macros.
  3. Finally restart your Outlook to activate the new VBA project.
  4. From now on, every time when you send an email out, its attachments will be deleted automatically, like the following screenshot:Attachments Get Removed after Sending

Resolve Outlook Issues in Time

It is an unquestioned fact that Outlook is error prone. Therefore, if you would like to protect your Outlook data from loss or corruption, you have to spend a lot of efforts, including making regular data backups and keeping a robust Outlook fix tool in vicinity, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupt mdf and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *