MojoDK
MojoDK

Reputation: 4528

Can't delete attachments from Outlook.MailItem

My Outlook addin checks (when user click "send") if a large attachment is attached. If so it should remove it and cancel the sending and give focus back to the user.

Here's a sample of my Outlook addin code...

Private Sub ThisApplication_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
    Dim mail As Outlook.MailItem = CType(Me.Application.ActiveInspector.CurrentItem, Outlook.MailItem)
    For i As Integer = mail.Attachments.Count To 1 Step -1
        mail.Attachments.Remove(i)
    Next
    Cancel = True
End Sub

The active mail item still shows all the attachements. :(

How do I get Outlook to remove all the attachments (before user sends the mail) and cancel the sending?

Thanks a million!

Mojo

Upvotes: 3

Views: 2478

Answers (2)

KuleRucket
KuleRucket

Reputation: 93

Old question I know but I have the same problem with Outlook 2010 and solved it. Neither Delete nor Remove worked for me until I added:

mail.Save

Upvotes: 1

tmountjr
tmountjr

Reputation: 1475

Try this:

Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
    Dim mail As Outlook.MailItem = CType(Me.Application.ActiveInspector.CurrentItem, Outlook.MailItem)
    For Each a As Outlook.Attachment In mail.Attachments
        a.Delete()
    Next
    Cancel = True
End Sub

Upvotes: 1

Related Questions