How to Import Contacts From MSN Messenger Using a Hotmail Email Address



This guide will show you how to take a users hotmail email address and download or import their contacts programmatically using ASP.NET.

This kind of feature is useful if you are building a Web 2.0 website, a social networking website or anything like that which can benefit from users being able to easily import their contacts from MSN Messenger into your website. You can see this type of functionality on many websites today including MySpace, Facebook and Groupbox. I mentioned Groupbox because that is of course my website. Groupbox is a website for online groups and the feature you are about to learn is one that I implemented to make it easy for users to import their MSN messenger contacts.

After reading this guide you will be able to: Import a users contacts from MSN Messenger using their MSN Hotmail email address and MSN Password.

What you will need: I'll need to assume you know a bit about programming on the web, the .NET framework, and in this case some VB.NET.

Much of the work for importing contacts from MSN Messenger has been done for you by a group called XIH. They have a class library named the DotMSN Messaging library. We will need this class library so I've included a link to my blog where you can download it at the bottom of the article.

The class library does many things but we are just going to use it to retrieve a users contact email addresses.

Importing contacts from MSN MessengerWe are going to achieve this by creating a function that will return an ArrayList of email address' that you can then use in your website.Here is the function I'm using that imports the contacts and returns them as an ArrayList :


Public Shared Function GetMessengerContacts (ByVal username As String, ByVal password As String) As ArrayList

Dim sEmail As String = username

Dim sPassword As String = password

Dim sConnected As Boolean

Dim iCountactsFound As Integer

Dim aReturn As New ArrayList

Dim DotMSN As XihSolutions.DotMSN.Messenger = New XihSolutions.DotMSN.Messenger

DotMSN.Credentials.Account = sEmail

DotMSN.Credentials.Password = sPassword

DotMSN.Credentials.ClientID = ""

DotMSN.Credentials.ClientCode = "Q1P7W2E4J9R8U3S5"


DotMSN.Connect ()

System.Threading.Thread.Sleep (10000)

sConnected = DotMSN.Connected

For Each contact As XihSolutions.DotMSN.Contact In DotMSN.ContactList.All

aReturn.Add (contact.Mail)

iCountactsFound = iCountactsFound + 1


DotMSN.Disconnect ()

Catch ex As Exception

'There was an error

End Try

Return aReturn

End Function


As you can see it makes use of the DotMSN class library so make sure you have the XihSolutions.DotMSN.dll in your bin directory.

You will notice two things you may not have been expecting, firstly that the MSN network requires a 'ClientID' and 'ClientCode'. Feel free to use the ones I've provided here. Take note thou that these may become invalid in the future so if that is the case, either contact me or do a search for some new ones. I've been using these credentials for a couple of years without problem.

Secondly, the line that reads System.Threading.Thread.Sleep (10000) may have caught your attention. Without this 10 second pause, I've found that only a portion of the contacts are downloaded. Obviously the DotMSN function runs asynchronously and as a result, I put this pause in to let it catch up. There are probably neater ways of doing this but because any given user only imports their contacts from time to time it does not seem to be a problem.Third, you should capture the user's username and password in a secure environment.


Simple stuff is not it – you'll need to tool up a page that can pass the email address and password to the function but that is very simple and does not need explanation. Additionally, you'll need to make use of the ArrayList once it is populated with email addresses – again this is easy: you may want to store them in a database or send email invitation to each email address, or both.


Leave a Reply