VB Code To Loop Through Sent Items And Extract Recipients Email Addresses
Posted on 2006-10-24
I need a quick way of scanning a users sent items and extracting all the recipient email addresses (as strings) and saving them to a database. I'm not used to VB app programming and am having real trouble finding a way of extracting the recipient email address(es) as a string from a mailitem object. Basically I can't find the right property of the mailitem object - I have tried the recipient (and recipient.addressitem) property but this doesn't work - Run time error '438', Object doesn't support this property or method. I suspect this is because the property is not of a string type and the variable and the email_addresses variable is. I just can't find the property I need in any of the help files! Or don't know how to convert the property to a string. I'm using the following code (I will add in the code to extract and save to the DB later).
Dim myOlApp As Outlook.Application
Dim SentItems As Outlook.MAPIFolder
Dim obj As Outlook.MailItem
Dim email_addresses As String
Dim i As Integer
Set myOlApp = CreateObject("Outlook.Application")
Set SentItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)
For i = 1 To SentItems.Items.Count
If SentItems.Items(i).Class = olMail Then
Set obj = SentItems.Items.Item(i)
email_addresses = obj.Recipient 'this is where it fails
Please help this is doing my head in!!!