Understanding Hotmail’s HTTPMail Protocol
When building a mail client for a web‑based service like Hotmail, the first hurdle is figuring out how the service exposes its data. Unlike the widely supported POP3 or IMAP4 protocols, Hotmail historically did not provide a standard gateway. That meant developers had to reverse‑engineer the traffic generated by Microsoft’s own client, Outlook Express, to discover the hidden API. The result is the HTTPMail protocol - a WebDAV‑based extension that works over plain HTTP/1.1. It was never formally documented, but its behavior is consistent enough that developers can write code that talks to it reliably.
At its core, HTTPMail behaves like any other WebDAV service. The client sends a PROPFIND request to ask for properties of a resource, and the server replies with XML that describes the resource. For a Hotmail mailbox, the initial PROPFIND is aimed at the generic Hotmail service URL: http://services.msn.com/svcs/hotmail/httpmail.asp. The response includes links to all of the user’s folders - Inbox, Sent Items, Drafts, etc. - and a handful of service‑specific properties such as adbar (advertising bar) and maxpoll (maximum polling interval).
Once the client has the folder URLs, further PROPFIND requests can be sent against those URLs to pull lists of mail items. Each mail item is represented by an HTTP resource whose URL is also returned in the XML. To fetch the body of a message, a simple HTTP GET is performed against that URL. Sending a message follows a different path: a POST is issued against the sendmsg folder URL, with the message body formatted according to RFC 821. The POST must include a Content‑Type: message/rfc821 header so the server knows how to parse the payload.
Because HTTPMail is essentially a thin wrapper around standard HTTP methods, most of the heavy lifting - authentication, redirect handling, cookie management - is delegated to the underlying HTTP client library. For .NET developers, the MSXML2.XMLHTTP COM object is a convenient choice because it implements the necessary HTTP/1.1 features out of the box and exposes a straightforward API for setting headers and reading responses.
In the following sections, we will walk through the steps needed to build a complete Hotmail client in C#. We’ll start by setting up the development environment, then move through connecting to the gateway, parsing the XML responses, enumerating mail items, and finally retrieving and sending messages. Each step is illustrated with real code snippets that you can copy into your own project.
Preparing the C# Development Environment
To talk to Hotmail’s HTTPMail service from a .NET application, you need two main pieces of infrastructure: the .NET framework itself and the MSXML2 COM library. The MSXML2 library ships with Windows and provides a ready‑made XMLHTTP object that you can use to send HTTP requests. In Visual Studio, you add a reference to the library by right‑clicking the project, selecting Add Reference…, navigating to the COM tab, and choosing Microsoft XML, v6.0 (or the highest version available). Once added, the Interop assembly is generated automatically, giving you a MSXML2.XMLHTTP type that you can instantiate in code.
Next, create a console application for simplicity. Even though the sample demonstrates a command‑line tool, the same code can be reused in a Windows Forms or WPF client; only the UI logic changes. Add the following using directive at the top of your main file so you can reference the COM type directly:
Now declare a field to hold the XMLHTTP instance:
The constructor of your main class should instantiate this field:
With the HTTP client ready, the next step is to build the PROPFIND request that initiates communication with Hotmail. The request body is a small XML document that lists the properties you want to retrieve. Because Hotmail is sensitive to the exact XML namespace declarations, keep the request exactly as shown:
Notice that the XML is a single string literal. This preserves line breaks and indentation, which some servers tolerate but others do not. The key is that the namespaces match the server’s expectations.
Once you have the XML, you can open the connection to the Hotmail gateway. The URL for the service is fixed:
Use the open method of XMLHTTP to set up the request. The first parameter is the HTTP method - PROPFIND in this case. The third parameter indicates whether the call is asynchronous. For a console app we use false to keep the flow synchronous. Authentication is passed as the username and password. If you omit them, XMLHTTP will pop up a Windows login dialog, which is not desirable for automated clients.
After opening, you need to add the XML body to the request. The setRequestHeader method can be used to attach the XML directly, but the standard way is to call send with the XML string as the body:
When send completes, the response can be read from responseText. At this point the client has authenticated and has a list of folder URLs.
Parsing the Folder List Returned by Hotmail
The XML returned by the initial PROPFIND contains several hm:* elements, each holding the full URL to a particular folder. The XML follows a standard WebDAV multistatus structure: a response element for each property, each containing a href and a propstat. Hotmail embeds the folder URL directly inside the hm:inbox or hm:sendmsg elements, so the parser can look for those tags and extract their values.
Because the XML is fairly predictable, the fastest approach is to use XmlTextReader for forward‑only, non‑schema validation parsing. Wrap the raw XML string in a StringReader to feed it to the reader:
Iterate through the nodes until you encounter an element named hm:inbox or hm:sendmsg. When you hit an element, read its next node to get the value. The pattern looks like this:
After the loop, inboxUrl and sendUrl hold session‑valid URLs that the client can reuse for subsequent operations. They remain valid for the duration of the session and can be used to perform folder queries, fetch individual messages, or send new mail.
Listing Mail Items in a Folder
With a folder URL in hand, the next task is to enumerate the messages it contains. A second PROPFIND request is sent against the folder URL, requesting properties that describe each item. The request body is a slightly different XML document that asks for a set of header fields plus the isfolder and read flags. Here is the XML used in the sample:
The client opens the connection to the folder URL using PROPFIND, but this time the The returned XML contains a Again, After the loop completes, To view or download a message, the client performs a simple HTTP GET against the URL stored in the The method uses synchronous I/O, which is fine for a console demo. In a UI application, you would want to run the call asynchronously or on a background thread to keep the interface responsive. The raw RFC 821 string can be parsed further to extract individual headers or display the body in a rich text box. Sending mail via HTTPMail mimics the SMTP conversation that Outlook Express would have performed. The client builds a plain text body that contains the SMTP commands ( First, format the header section. The example below uses a simple, hard‑coded format that includes the necessary fields. In production code you would want to escape quotes and special characters, and handle multiple recipients: Once the body is assembled, the client prepares a POST request. The After the POST completes, the server will queue the message for delivery. The HTTP response status (200 OK or 202 Accepted) can be checked via To bring all of the pieces together, the console program follows a straightforward flow: prompt the user for credentials, connect to the Hotmail gateway, parse the folder URLs, list the inbox messages, optionally display a selected message, and offer a menu to send a new mail. Each step uses the helper methods described earlier. When deploying or sharing the application, keep in mind the following practical tips: • Authentication: Hotmail requires Basic authentication over HTTP. If you encounter 401 responses, double‑check that the username includes the full Hotmail address (e.g., user@hotmail.com) and that the password is current. Some accounts have two‑factor protection that will reject basic logins; consider using an app‑specific password if available. • Session Persistence: The folder URLs you retrieve are only valid for the duration of the authenticated session. If you want to maintain a long‑running client, keep the XMLHTTP object alive and reuse the same instance for all requests. Do not create a new XMLHTTP per call unless you have a good reason. • Error Handling: The XMLHTTP object exposes an • Performance: While XMLHTTP is convenient, it is a COM wrapper and can be slower than .NET’s native HttpClient. For production use, consider writing a thin wrapper around HttpClient that mimics XMLHTTP’s behavior but benefits from the latest HTTP/2 support and async I/O. • Encoding: Hotmail’s responses use Windows‑1252 encoding by default. If you encounter garbled characters, set By following these guidelines and using the code snippets provided, you can build a functional Hotmail client that talks directly to Microsoft’s HTTPMail service. The approach is extensible - add support for additional folders, implement MIME parsing for attachments, or replace the console UI with a richer desktop application - all while keeping the core protocol handling identical.username and password parameters are left blank because authentication was handled during the first request. The XML is sent as the body, and the response is captured from responseText
response element for each message. Inside each response you’ll find a href that points to the message resource, and a propstat that includes all of the requested properties. To make sense of this data, the sample code defines a simple MailItem class that holds the relevant fields.XmlTextReader is used for speed. The loop follows a clear pattern: on encountering a D:response start element, create a new MailItem. On each property element inside the response, read the value and assign it to the appropriate field. When the D:response end element is reached, add the fully populated MailItem to a collection.mailItems contains a complete list of messages, each represented by a MailItem with URL, read flag, headers, and size. This structure is ready for display or further processing.Retrieving the Body of a Mail Message
MailItem. The GET returns the message in plain RFC 821 format, including headers and body separated by a blank line. The sample code encapsulates this logic in a helper method that takes a MailItem and returns the raw text:Composing and Sending a New Message
MAIL FROM, RCPT TO, DATA), header fields (From, To, Subject, Date), and the message content. The entire payload is sent in a single POST request to the sendmsg URL retrieved earlier.Content‑Type header must be set to message/rfc821 so the server knows to treat the payload as an SMTP session. The open call omits credentials because the session was already authenticated:status or statusText if error handling is desired.Running the Console Client and Common Pitfalls
status property. A status of 302 indicates a redirect that XMLHTTP handled automatically. A 403 or 404 points to permission issues or malformed URLs. Capture statusText and log it for debugging.xmlHttp_.setOption(6, 0) (the constant for option HTTP\_REQUEST\_HEADERS) or manually convert the byte stream using Encoding.GetEncoding("windows-1252") before creating the string.





No comments yet. Be the first to comment!