Skip to main content

How to automatically remove the attachments after emails sending from the sent items?

When sending email with some attachments, the attachments will be stored with the emails into the sent items folder by default. To reduce the size of your PST file, you may want to remove the attachments from the sent items automatically after emails sending. This article, I will talk about this task in Outlook.

Automatically remove the attachments after emails sending from the sent items


Automatically remove the attachments after emails sending from the sent items

The following VBA code can help you to auto delete the attachments after emails sending from your Outlook, please do as this:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession from the Project1(VbaProject.OTM) pane to open the mode, and then copy and paste the following code into the blank module.

VBA code: Auto remove attachments after emails sending from the sent items:

Public WithEvents SentMailItems As Outlook.Items
    Private Sub Application_Startup()
    Set SentMailItems = Outlook.Application.Session.GetDefaultFolder(olFolderSentMail).Items
    End Sub
    Sub SentMailItems_ItemAdd(ByVal Item As Object)
    Dim xSentMail As Outlook.MailItem
    Dim xAttachments As Outlook.Attachments
    Dim xAttachment As Outlook.Attachment
    Dim xAttachmentInfo As String
    On Error Resume Next
    If Item.Class = olMail Then
       Set xSentMail = Item
    End If
    Set xAttachments = xSentMail.Attachments
    For i = xAttachments.Count To 1 Step -1
        Set xAttachment = xAttachments.Item(i)
        xAttachmentInfo = "<HTML><BODY>" & xAttachment.DisplayName & _
                          "</BODY></HTML>" & vbCrLf & xAttachmentInfo
        xAttachment.Delete
    Next
    xSentMail.HTMLBody = "<HTML><BODY><font color=#FF0000>Attachment Removed: </font><br/></BODY></HTML>" & _
                         xAttachmentInfo & "<HTML><BODY><br/></BODY></HTML>" & xSentMail.HTMLBody
    xSentMail.Save
End Sub

3. After inserting the above code, please restart your Outlook to make the code take effect.

4. From now on, when you send emails with attachments, the attachments will be deleted automatically from the sent items as following screenshot shown:

Note: This code is only available to the default data account.


Best Office Productivity Tools

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

βœ” Email Automation: Auto Reply (Out of Office)  /  Schedule Send emails  /  Auto CC/BCC  /  Advanced Auto Forward  /  Auto Add Greating ...

βœ‰ Email Management: Easily Recall Emails  /  Block Scam Emails  /  Delete Duplicate Emails  /  πŸ”ŽAdvanced Search  /  Consolidate Folders ...

πŸ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface & Interaction Magic: 😊More Pretty and Cool Emojis   /  Brings Browser Tabs Right Into Your Outlook  /  Minimize Outlook Instead of Closing ...

πŸ‘ One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  πŸ•˜Show Sender's Time Zone  /  Send to Recipients Separately ...

πŸ‘©πŸΌβ€πŸ€β€πŸ‘©πŸ» Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Over 100 Features Await Your Exploration! Click Here to Discover More.

Read More       Free Download      Purchase
 
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations