Link to home
Start Free TrialLog in
Avatar of dcarrion
dcarrion

asked on

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(, , , , , , "10.0.1.11" & 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")
        oAddr.Update()

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
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial