Add a contact to mailbox using MAPI Session

Posted on 2006-05-19
Last Modified: 2008-02-07
Hello...All I want to do is get this damn thing to add a contact to a mailbox...I can't see what I am doing wrong.

        Dim oFolder As Object
        Dim oAddressEntries As Object
        Dim CdoPR_DISPLAY_NAME As Object
        Dim oFields As Object
        Dim oAddr As Object
        Dim CdoPR_EMAIL_ADDRESS As Object
        Dim CdoDefaultFolderContacts As Object

        Dim CDOSession As Object = CreateObject("MAPI.Session")
        CDOSession.Logon(, , , , , , "" & vbLf & "Somones Mailbox")
        oFolder = CDOSession.GetDefaultFolder(CdoDefaultFolderContacts)
        oAddressEntries = oFolder.Messages
        oAddr = oAddressEntries.Add(, , "IPM.Contact") <============= THIS ONE
        oFields = oAddr.Fields
        oFields.Add(CdoPR_DISPLAY_NAME, "Someones Name")
        oFields.Add(CdoPR_EMAIL_ADDRESS, "")

It works when I use the NameSpace but not MAPI.Session. The error is:

An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in microsoft.visualbasic.dll

Additional information: Invalid number of parameters.

On the line with the arrow ^

I really want to do it this way because I don't want to use the Outlook client...Please help this is urgent for a project I am doing...Thanks for your help
Question by:dcarrion
    1 Comment
    LVL 96

    Accepted Solution

    What are you working with here?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now