Solved

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

Posted on 2006-10-24
3
751 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 500 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

Windows running painfully slow? Try these tips..

Stay away from Speed Up Computer Programs that do more harm than good.
Try these tips instead.
Step by step instructions in trouble shooting Windows Performance issues.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

752 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