How can I access Microsoft Outlook contacts using ASP.NET? Are there any controls that can do this?
You would need to create an ActiveX Application that the client would install to allow you access to this. Unless it's an internal development project, don't expect people to install something that gives you access to their email program.
If by control you mean api, there already is one - Exchange Web Services (EWS). Assuming you are dealing with exchange, and have EWS set up. The web services usually sit at:
https://[yourmaildomain.com]/EWS/Exchange.asmx
Here is some quick code - not production tested (also in vb.net)
Dim esb As New ExchangeServiceBinding()
esb.Credentials = New NetworkCredential("someusername", "somepassword")
esb.Url = "https://[yourmaildomain.com]/EWS/Exchange.asmx"
Dim addressType As New EmailAddressType()
With addressType
.EmailAddress = "[email protected]"
.MailboxType = MailboxTypeType.Mailbox
.MailboxTypeSpecified = True
End With
' properties
Dim itemProperties As New ItemResponseShapeType()
itemProperties.BaseShape = DefaultShapeNamesType.AllProperties
' Identify which folders to search to find items.
Dim folderIDs(0) As DistinguishedFolderIdType
folderIDs(0) = New DistinguishedFolderIdType()
folderIDs(0).Id = DistinguishedFolderIdNameType.contacts
folderIDs(0).Mailbox = addressType
Dim findItemRequest As New FindItemType()
findItemRequest.Traversal = ItemQueryTraversalType.Shallow
findItemRequest.ItemShape = itemProperties
findItemRequest.ParentFolderIds = folderIDs
' send request
Dim findItemResponse As FindItemResponseType = esb.FindItem(findItemRequest)
Dim rmta As ResponseMessageType() = findItemResponse.ResponseMessages.Items
For Each rmt As ResponseMessageType In rmta
If rmt.ResponseClass = ResponseClassType.Success Then
Dim firmt As FindItemResponseMessageType = CType(rmt, FindItemResponseMessageType)
If firmt IsNot Nothing Then
Dim root As FindItemParentType = firmt.RootFolder
Dim obj As Object = root.Item
If TypeOf obj Is ArrayOfRealItemsType Then
Dim items As ArrayOfRealItemsType = DirectCast(obj, ArrayOfRealItemsType)
If items.Items IsNot Nothing Then
For Each it As ItemType In items.Items
If TypeOf it Is ContactItemType Then
Dim cit As ContactItemType = DirectCast(it, ContactItemType)
Response.Write("<p>")
Response.Write(cit.Subject)
Response.Write("<p>")
End If
Next
End If
End If
End If
End If
Next
FROM Microsoft Support:
How to use the Microsoft Outlook Object Library to retrieve a contact by using Visual C#
MSDN:
How to: Access Outlook Contacts (Some more nice how to's at the end)
StesCodes Contact Grabber have services for Gmail, Yahoo, MSN, Hotmail, AOL, AIM, Mail.com, Orkut, Myspace, Facebook, Google wave, Plaxo, Bigstring, Msn Messenger, Opera, kodak, evite, pingg, rediffmail, fastmail and more...
Also have application grabbing services for Outlook CSV, Outlook Express CSV, Thunderbird CSV, Google CSV, Yahoo CSV, Windows live CSV.
Click here to play with the DEMO and SOURCE CODE
- Stescodes uses no exe’s
- StesCodes uses no user redirection for permission
- StesCode source code will work both in shared and dedicated servers
- StesCodes provides code update
- 100% UI customizable
- Uses no OAuth
Source code available in Asp.net, VB.net, WinForms and Webservices for Framework 3.5 and 4.0