• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

Add a contact to mailbox using MAPI Session

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, "bla@seanmccormick.com")

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
1 Solution
Bob LearnedCommented:
What are you working with here?


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now