Creating a Contact in the Exchange Store (WebDAV)
Creating a Contact in the Exchange Store (WebDAV)
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Creating a contact involves setting informational properties and saving the contact to the Exchange store.
Example
The following example uses the PROPPATCH Method to create a contact for "JoLynn Dobney" and save it to a user's Contacts folder in the Exchange store.
Note If a contact item of the same name currently exists, it will be modified/overwritten.
See Constructing Exchange Store HTTP URLs and Authentication and Security Using WebDAV for more information.
VBScript
' Declare variables to be used. Dim objRequest 'As MSXML.XMLHTTPRequest Dim strBody 'As String Dim strXMLNSInfo 'As String Dim strNameInfo 'As String Dim strBusinessAddrInfo 'As String Dim strHomeAddrInfo 'As String Dim strOtherAddrInfo 'As String Dim strMailAddrInfo 'As String Dim strPhoneInfo 'As String Dim strEmailInfo 'As String Dim strOrganizationalInfo 'As String Dim strPersonalInfo 'As String Dim strCustomerInfo 'As String Dim strFollowUpInfo 'As String Dim strMiscInfo 'As String Dim strUserFieldsInfo 'As String Dim strURL 'As String ' Specify the URL of the new object to be created. strURL = "https://ServerName/Exchange/UserName/Contacts/JoLynnDobney.eml" ' Create an HTTP request object. Set objRequest = CreateObject("Microsoft.xmlhttp") ' Specify the namespaces to be used. strXMLNSInfo = "xmlns:g=""DAV:"" " & _ "xmlns:c=""urn:schemas:contacts:"" " & _ "xmlns:e=""https://schemas.microsoft.com/exchange/"" " & _ "xmlns:mapi=""https://schemas.microsoft.com/mapi/"" " & _ "xmlns:x=""xml:"" xmlns:cal=""urn:schemas:calendar:"" " & _ "xmlns:mail=""urn:schemas:httpmail:"">" ' Specify the contact's name information. ' (First Name, Middle Name, Last Name, Full Name, ' Subject of the contact--used by Outlook Address Book, ' File As, Initials, Nickname, Title, and Suffix) strNameInfo = "<c:givenName>JoLynn</c:givenName>" & _ "<c:middlename>Julie</c:middlename>" & _ "<c:sn>Dobney</c:sn>" & _ "<c:cn>JoLynn J. Dobney</c:cn>" & _ "<mail:subject>JoLynn Dobney</mail:subject>" & _ "<c:fileas>Dobney, JoLynn</c:fileas>" & _ "<c:initials>JJD</c:initials>" & _ "<c:nickname>Jo</c:nickname>" & _ "<c:personaltitle>Mrs.</c:personaltitle>" & _ "<c:namesuffix>MCSD</c:namesuffix>" ' Specify the Business Address information. ' (Street, PO Box, City, State, Postal Code, and Country) strBusinessAddrInfo = "<c:street>100 Main Street</c:street>" & _ "<c:postofficebox>PO Box 12345</c:postofficebox>" & _ "<c:l>AnyTown</c:l>" & _ "<c:st>WA</c:st>" & _ "<c:postalcode>12345-1234</c:postalcode>" & _ "<c:co>USA</c:co>" ' Specify the Home Address information. ' (Street, PO Box, City, State, Postal Code, and Country) strHomeAddrInfo = "<c:homeStreet>500 Main Street</c:homeStreet>" & _ "<c:homepostofficebox>PO Box 54321</c:homepostofficebox>" & _ "<c:homeCity>SomeTown</c:homeCity>" & _ "<c:homeState>WA</c:homeState>" & _ "<c:homePostalCode>12345</c:homePostalCode>" & _ "<c:homeCountry>USA</c:homeCountry>" ' Specify the Other Address information. ' (Street, PO Box, City, State, Postal Code, and Country) strOtherAddrInfo = "<c:otherstreet>99 Water St</c:otherstreet>" & _ "<c:otherpostofficebox>PO Box 98765</c:otherpostofficebox>" & _ "<c:othercity>SomeTown</c:othercity>" & _ "<c:otherstate>FL</c:otherstate>" & _ "<c:otherpostalcode>12345</c:otherpostalcode>" & _ "<c:othercountry>USA</c:othercountry>" ' Specify which address is the mailing address. ' 0 = None, 1 = Home, 2 = Business, 3 = Other strMailAddrInfo = "<c:mailingaddressid>2</c:mailingaddressid>" ' Specify phone number information. ' (Business Phone, Business Phone 2, Business Fax, ' Home Phone, Home Phone 2, Home Fax, ' Other Phone, Other Fax, Pager, Mobile Phone, ' Car Phone, ISDN, Telex, TTY/TDD, Callback) strPhoneInfo = "<c:telephoneNumber>425-555-1110</c:telephoneNumber>" & _ "<c:telephonenumber2>425-555-1111</c:telephonenumber2>" & _ "<c:facsimiletelephonenumber>425-555-1112</c:facsimiletelephonenumber>" & _ "<c:homePhone>425-555-1113</c:homePhone>" & _ "<c:homephone2>425-555-1114</c:homephone2>" & _ "<c:homefax>425-555-1115</c:homefax>" & _ "<c:otherTelephone>800-555-1111</c:otherTelephone>" & _ "<c:otherfax>800-555-1112</c:otherfax>" & _ "<c:pager>425-555-1116</c:pager>" & _ "<c:mobile>425-555-1117</c:mobile>" & _ "<c:othermobile>804-555-1113</c:othermobile>" & _ "<c:internationalisdnnumber>425-555-1118</c:internationalisdnnumber>" & _ "<c:telexnumber>425-555-1119</c:telexnumber>" & _ "<c:ttytddphone>425-555-1120</c:ttytddphone>" & _ "<c:callbackphone>425-555-1121</c:callbackphone>" ' Specify the e-mail address information. strEmailInfo = "<mapi:emaillisttype>1</mapi:emaillisttype>" & _ "<mapi:email1addrtype>EX</mapi:email1addrtype>" & _ "<mapi:email1emailaddress>" & _ "/o=Microsoft/ou=First Administrative Group/cn=Recipients/cn=jdobney" & _ "</mapi:email1emailaddress>" & _ "<mapi:email1originaldisplayname>" & _ "JoLynn Dobney (Exchange)" & _ "</mapi:email1originaldisplayname>" & _ "<mapi:email2addrtype>SMTP</mapi:email2addrtype>" & _ "<mapi:email2emailaddress>" & _ "JoLynn.Dobney@domain.fourthcoffee.com" & _ "</mapi:email2emailaddress>" & _ "<mapi:email2originaldisplayname>" & _ "JoLynn Dobney (SMTP)" & _ "</mapi:email2originaldisplayname>" & _ "<mapi:email3addrtype>X400</mapi:email3addrtype>" & _ "<mapi:email3emailaddress>" & _ "c=us;a= ;p=Microsoft;o=Exchange;s=Dobney;g=JoLynn;i=J;" & _ "</mapi:email3emailaddress>" & _ "<mapi:email3originaldisplayname>" & _ "JoLynn Dobney (X400)" & _ "</mapi:email3originaldisplayname>" ' Specify organizational information. ' (Company, Company Main Phone, Business Home Page, ' Department, Job Title, Manager's Name, ' Assistant's Name, Assistant's Phone, Office Location, ' Organizational ID Number, Computer Network Name, ' Profession) strOrganizationalInfo = "<c:o>Fourth Coffee</c:o>" & _ "<c:organizationmainphone>425-555-8080</c:organizationmainphone>" & _ "<c:businesshomepage>http://www.fourthcoffee.com</c:businesshomepage>" & _ "<c:department>YYY</c:department>" & _ "<c:title>Lead Software Design Engineer</c:title>" & _ "<c:manager>Karan Khanna</c:manager>" & _ "<c:secretarycn>Ken Myer</c:secretarycn>" & _ "<c:secretaryphone>425-555-1122</c:secretaryphone>" & _ "<c:roomnumber>C-309</c:roomnumber>" & _ "<c:employeenumber>987654321</c:employeenumber>" & _ "<c:computernetworkname>jdobney</c:computernetworkname>" & _ "<c:profession>Software Designer</c:profession>" ' Specify personal information. ' (Birthday, Anniversary, Spouse, Children, Gender, ' Personal Home Page, Hobbies) strPersonalInfo = "<c:bday>1974-01-01T08:00:00Z</c:bday>" & _ "<c:weddinganniversary>1995-01-01T08:00:00Z</c:weddinganniversary>" & _ "<c:spousecn>Barry Johnson</c:spousecn>" & _ "<c:childrensnames>" & _ "<x:v>David Johnson</x:v><x:v>Willis Johnson</x:v>" & _ "</c:childrensnames>" & _ "<c:gender>Male</c:gender>" & _ "<c:personalHomePage>" & _ "http://www.example.com/JoLynnDobney/default.htm" & _ "</c:personalHomePage>" & _ "<c:hobbies>Reading, lawn bowling.</c:hobbies>" ' Specify customer related information. ' (Customer ID, Account, Billing Information) strCustomerInfo = "<c:customerid>YYY</c:customerid>" & _ "<c:account>YYY</c:account>" & _ "<c:billinginformation>YYY</c:billinginformation>" ' Specify Follow Up/Reminder information. ' (Reminder, Reminder Topic, Reminder Time, etc.) strFollowUpInfo = "<mapi:reminderset>1</mapi:reminderset>" & _ "<mapi:request>Call</mapi:request>" & _ "<mapi:remindertime>2001-12-01T08:00:00Z</mapi:remindertime>" & _ "<mapi:remindernexttime>2001-12-01T08:00:00Z</mapi:remindernexttime>" & _ "<e:reply-by-iso>2001-12-01T08:00:00Z</e:reply-by-iso>" ' Specify miscellaneous information. ' (Categories, Contacts, Mileage, FTP Site, Language, ' Government ID, Location, Internet Free/Busy Address, ' Sensitivity) strMiscInfo = "<e:keywords-utf8>" & _ "<x:v>Buddies</x:v><x:v>Engineers</x:v>" & _ "</e:keywords-utf8>" & _ "<mapi:contacts><x:v>Brian Johnson</x:v></mapi:contacts>" & _ "<e:mileage>Rarely used string property</e:mileage>" & _ "<c:ftpsite>ftp://ftp.example.com/</c:ftpsite>" & _ "<c:language>US English</c:language>" & _ "<c:governmentid>000-00-0000</c:governmentid>" & _ "<c:location>Nowhere Land</c:location>" & _ "<cal:fburl>http://www.example.com/JoLynnDobney/freebusy</cal:fburl>" & _ "<mapi:sensitivity>2</mapi:sensitivity>" ' Specify User Field information. ' (User Field 1, User Field 2, User Field 3, User Field 4) strUserFieldsInfo = "<e:extensionattribute1>User Data 1" & _ "</e:extensionattribute1>" & _ "<e:extensionattribute2>User Data 2</e:extensionattribute2>" & _ "<e:extensionattribute3>User Data 3</e:extensionattribute3>" & _ "<e:extensionattribute4>User Data 4</e:extensionattribute4>" ' Put it all together in an HTTP request. strBody = "<?xml version=""1.0""?>" & _ "<g:propertyupdate " & strXMLNSInfo & _ "<g:set>" & _ "<g:prop>" & _ "<g:contentclass>urn:content-classes:person</g:contentclass>" & _ "<e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>" & _ strNameInfo & strBusinessAddrInfo & _ strHomeAddrInfo & strOtherAddrInfo & _ strMailAddrInfo & strPhoneInfo & _ strEmailInfo & strOrganizationalInfo & _ strPersonalInfo & strCustomerInfo & _ strFollowUpInfo & strMiscInfo & _ strUserFieldsInfo & _ "</g:prop>" & _ "</g:set>" & _ "</g:propertyupdate>" ' Open the request object, assigning it the method PROPPATCH. objRequest.open "PROPPATCH", strURL, False, "UserName", "Password" ' Set the necessary headers for the request. objRequest.setRequestHeader "Content-Type", "text/xml" objRequest.setRequestHeader "Translate", "f" objRequest.setRequestHeader "Content-Length", Len(strBody) ' Send the request, using the XML document as the body. objRequest.send strBody 'Display the results. If (objRequest.Status >= 200 And objRequest.Status < 300) Then MsgBox "Success! " & "Results = " & objRequest.Status & _ ": " & objRequest.statusText ElseIf objRequest.Status = 401 Then MsgBox "You don't have permission to create the contact. " & _ "Please check your permissions on this item." ElseIf (objRequest.Status >= 500 And objRequest.Status < 600) Then MsgBox "An error occurred on the server." Else MsgBox "Request Failed. Results = " & objRequest.Status & _ ": " & objRequest.statusText End If Set objRequest = Nothing
Related Topics
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.