Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Code To Loop Through Sent Items And Extract Recipients Email Addresses

Posted on 2006-10-24
3
Medium Priority
?
757 Views
Last Modified: 2012-06-27
Hi,
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).

Sub HarvestSent()
 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
  End If
 Next
End Sub

Please help this is doing my head in!!!

Thanks.
0
Comment
Question by:ShinyApples
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 2000 total points
ID: 17795781
Shiny Apples,

Bear in mind, this will likely trigger the outlook security warning.  Consider using the Redemption object instead to avoid it: http://www.dimastr.com/redemption/home.htm

But you need to get the .address of the .recipient

Sub HarvestSent()
 Dim myOlApp As Outlook.Application
 Dim SentItems As Outlook.MAPIFolder
 Dim email_addresses As String
 Dim i As Integer, j As Integer
 Set myOlApp = CreateObject("Outlook.Application")
 Set SentItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)
 For i = 1 To SentItems.Items.Count
  If TypeName(SentItems.Items(i)) = "MailItem" Then
   For j = 1 To SentItems.Items.Item(i).Recipients.Count
    email_addresses = SentItems.Items.Item(i).Recipients(j).Address
    Debug.Print email_addresses
   Next
  End If
 Next
 Set SentItems = Nothing
 Set myOlApp = Nothing
End Sub

If you want the name of the recipient, use .AddressEntry

Matt
0
 

Author Comment

by:ShinyApples
ID: 17796842
Thank you very much matt that worked perfectly. The points are yours!

0
 
LVL 35

Expert Comment

by:mvidas
ID: 17796857
Glad to help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Changing a few Outlook Options can help keep you organized!
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question