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

x
?
Solved

Automatically add to contacts from a list of emails

Posted on 2007-03-21
7
Medium Priority
?
223 Views
Last Modified: 2010-04-16
Hi

I have been requested to find a way to automatically add to contacts a separate contact for each email address in a huge inbox of well over 10000 items. I can see a script that automatically adds addresses when you reply, but this isnt feasible as we would have to reply to each and every email that needs to be added. Is there a script that can scan an inbox for unique addresses and create a contact for each one?

Many thanks
0
Comment
Question by:5t34lth_G33k
[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
  • 5
  • 2
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 18763355
Yes, this is possible, but there is an issue you should be aware of.  Accessing any field that can contain an email address in any Outlook item is going to trigger a pop up warning that an application is accessing your mailbox and asking for permission to allow it to continue.  You can then grant the application permission for a fixed amount of time.  Beyond that, this is actually fairly simple.  One additional question, how do you plan to fill in the rest of the contact's details?  This is only going to produce a contact with an email address.  If you want to proceed, then I can put the script together before the end of the day.
0
 
LVL 7

Author Comment

by:5t34lth_G33k
ID: 18763918
That would be great, thanks. Can the first name and surname fields be populated by the name that preceeds the email address sometimes? Such as:

'John Smith[john.smith@company.com]'

If not, dont worry - just getting the email address should be good enough - the user can then manually add telephone numbers etc
0
 
LVL 76

Expert Comment

by:David Lee
ID: 18768900
Sorry, long day and I just saw your response.  I'll get to work on this in the morning.
0
A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

 
LVL 76

Expert Comment

by:David Lee
ID: 18769885
Here's the code for doing this.  Follow these instructions to use it.

1.  Open Outlook.
2.  Click Tools->Macro->Visual Basic Editor.  You should now be looking at the code editor.
3.  If not already expanded, expand Modules.  
4.  Click on Module1.
5.  Copy the code below and paste it into the right-hand window.
6.  Click the diskette icon on the toolbar to save the changes we just made.
7.  Click Tools->Macro->Security
8.  Set the security level to Medium.
9.  Click on a folder that contains emails.
10.  Run the macro (Tools->Macro->Macros, select AutoAddContact, and click Run).

The macro will process every message in the folder adding a new contact to your default contacts folder for each the sender of each message.  If the message included a sender name, then that name will be added to the contact along with the sender's email address.  Otherwise, the email address will be used for the contact's name.

Sub AutoAddContact()
    Dim olkContacts As MAPIFolder, _
        olkContact As ContactItem, _
        olkItem As Object, _
        olkReply As MailItem, _
        olkRecip As Recipient
    Set olkContacts = Application.Session.GetDefaultFolder(olFolderContacts)
    For Each olkItem In Application.ActiveExplorer.CurrentFolder.Items
        Set olkContact = Application.CreateItem(olContactItem)
        Set olkReply = olkItem.Reply
        Set olkRecip = olkReply.Recipients.Item(1)
        With olkContact
            .Email1Address = olkRecip.Address
            .FullName = olkItem.SenderName
            .Save
        End With
    Next
    Set olkContact = Nothing
    Set olkContacts = Nothing
    Set olkItem = Nothing
    Set olkReply = Nothing
    Set olkRecip = Nothing
End Sub
0
 
LVL 7

Author Comment

by:5t34lth_G33k
ID: 18779667
thanks for the code, but it seems to be adding duplicate contacts - is there a way to stop that?

Thanks!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 18779692
Sure.  I'll post a revised version shortly.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 18780253
Try this version.

Sub AutoAddContact()
    Dim olkContacts As MAPIFolder, _
        olkContact As ContactItem, _
        olkItem As Object, _
        olkReply As MailItem, _
        olkRecip As Recipient
    Set olkContacts = Application.Session.GetDefaultFolder(olFolderContacts)
    For Each olkItem In Application.ActiveExplorer.CurrentFolder.Items
        Set olkContact = olkContacts.Items.Find("[FullName] = " & Chr(34) & olkItem.SenderName & Chr(34))
        If TypeName(olkContact) = "Nothing" Then
            Set olkContact = Application.CreateItem(olContactItem)
            Set olkReply = olkItem.Reply
            Set olkRecip = olkReply.Recipients.Item(1)
            If Err = 0 Then
                strAddress = olkRecip.Address
                If strAddress = "" Then
                    strAddress = olkRecip.Name
                End If
            End If
            With olkContact
                .Email1Address = strAddress
                .FullName = olkItem.SenderName
                .Save
            End With
        End If
    Next
    Set olkContact = Nothing
    Set olkContacts = Nothing
    Set olkItem = Nothing
    Set olkReply = Nothing
    Set olkRecip = Nothing
End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
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: …

730 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