Delete Mail Attachments after sending Mail with Outlook 365

Add-in Express™ Support Service
That's what is more important than anything else

Delete Mail Attachments after sending Mail with Outlook 365
 
Hecht Juergen




Posts: 5
Joined: 2020-11-19
Hi all,

i have some problems with deleting files after sending mails. Currently i use the following Code to delete the attachments. Sometimes it works, but I can't really understand in which cases it works!


In my ThisAddn.vb i use
Private WithEvents mySentItems As Outlook.Items


in ThisAddIn_Startup()
mySentItems = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items


and this is my sub to delete the files.
    Private Sub mySentItems_ItemAdd(mail As Outlook.MailItem) Handles mySentItems.ItemAdd
        For i As Integer = mail.Attachments.Count To 1 Step -1
            mail.Attachments.Remove(i)
        Next
        mail.Save()
        Marshal.ReleaseComObject(mail)
    End Sub


It seems that there is a problem with syncing to the Microsoft O365 Exchange Server.

Is there anybody which can help me with this problem.

Regards
Juergen
Posted 01 Dec, 2020 04:30:23 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Juergen,

Your code leave unreleased a number of COM objects. Say, mail.Attachments.{something except for Add} produces the COM object representing the Attachments collection of that mail item; you need to release it.

I strongly recommend that you check section "Release all COM objects created in your code"; download the PDF at https://www.add-in-express.com/bitrix/rd.php?event1=download&event2=docs&event3=net&goto=/files/docs/adxnet93-update.pdf.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Dec, 2020 07:13:25 Top