Delete vcf Attachment from Incoming Emails

An attachment with a vcf file extension is a little calling card that comes along with some people’s email. Presumably, I can use that information to update my contacts quickly and easily. I’m not sure which email programs have this on by default, but I don’t think Outlook does. If it did, I would remember turning it off and I think I would be getting a ton more emails with vcf attachments.

It seems like an OK idea, but I have a few problems with it. First, Janet sent me 15 emails today (because it’s part of her job) and each one contained this attachment. If her personal information isn’t changing every 10 minutes, I don’t need that many cards. If it is, I don’t care. But the vcf file is only about 1/4 of a KB, so what’s the big deal. Two big deals:

Sometimes I use the little paperclip as a visual indicator to help me find a particular email. If I know that Janet sent me an attachment this morning, I can scan Janet’s emails and only read the subjects of the emails that have a paperclip. Except that all of her emails have the paperclip.

The other big deal, and the thing that pushed me to action, was using my macro to open Outlook attachments. I changed my code to always open the last attachment because embedded images show up first when you read in plain text, as I do. The vcf file, however, shows up last, so it screws me all up.

Anywho, I created this code to automatically delete a vcf attachment if one comes in. The code is in the ThisOutlookSession module and used the NewMail event to run whenever mail is received.

Private Sub Application_NewMail()
   
    Dim mi As MailItem
    Dim att As Attachment
   
    For Each mi In Me.GetNamespace(“MAPI”).GetDefaultFolder(olFolderInbox).Items
        If mi.Unread Then
            If mi.Attachments.Count > 0 Then
                For Each att In mi.Attachments
                    If Right$(att.FileName, 4) = “.vcf” Then
                        att.Delete
                        mi.Save
                        Exit For
                    End If
                Next att
            End If
        End If
    Next mi
   
   
End Sub

I’m not sure how to only deal with the new messages, so I process the whole Inbox. That’s not a big deal for me because I keep my Inbox clean, but it may be for you. I also assume there will not be more than on vcf attachment, which I think is pretty safe. If I had to deal with more than one attachment, I’d need to change that inner loop to something like

For i = mi.Attachments.Count to 1 Step -1
   Set att = mi.Attachments.Item(I)
   ‘do the rest
Next i

When you delete stuff from a collection, it’s always a good idea to work from the bottom up. Once I deal with the first vcf attachment, I exit the loop, so it’s not an issue for this application.

I’m sure there are some bugs I haven’t discovered, like when I get something in my inbox that’s not a MailItem object, but I’ll deal with those as they come. For now, I’m happy to be free of all those paperclips.

Posted in Uncategorized

2 thoughts on “Delete vcf Attachment from Incoming Emails

  1. I am getting this error: Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND).While deleting the “.vcf” attachment.

    Any suggestion ??


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.