Click here to Skip to main content
15,895,777 members
Articles / Programming Languages / C#

Hotmail using C# – A HTTPMail client under .NET

Rate me:
Please Sign up or sign in to vote.
4.83/5 (64 votes)
25 Mar 20038 min read 552.9K   2.3K   171  
A C# client library for access Hotmail using the undocumented HTTPMail protocol.
// HttpMail - Provides a .NET API for connecting to Hotmail.
// Copyright (C) Kais Dukes, 2003. All rights reserved. For
// futher information, contact: kaisdukes@hotmail.com

// Get the namespaces.
using System;
using System.Collections;

// Start the namespace.
namespace HttpMail
{
	/// <summary>
	/// Contains the main entry point.
	/// </summary>
	class EntryPoint
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			// Try for exceptions.
			try
			{
				// --- CONNECT ---------------------------------------------------------

				// Status.
				Console.WriteLine("Connecting to hotmail");

				// Initiate.
				string username = "USER@hotmail.com";
				string password = "PASSWORD";

				// Create the mail client.
				MailClient mailClient = new MailClient();

				// Connect to the server.
				mailClient.Connect(username, password);

				// --- GET INBOX -------------------------------------------------------

				// Status.
				Console.WriteLine("Accessing inbox");

				// Load the inbox.
				ArrayList mailItems = mailClient.LoadInbox();

				// Dump each mail.
				foreach(object obj in mailItems)
				{
					// Cast.
					MailItem mailItem = obj as MailItem;

					// Dump.
					Console.WriteLine(mailItem);
				}

				// --- READ MAIL -------------------------------------------------------

				// Now get the first e-mail.
				if(mailItems.Count > 0)
				{
					// Get the item.
					MailItem mailItem = mailItems[0] as MailItem;

					// Load the item.
					string mailData = mailClient.LoadMail(mailItem);

					// Dump the mail data.
					Console.WriteLine("-------------------------------------------------");
					Console.WriteLine("[" + mailData + "]");
				}

				// --- SEND MAIL -------------------------------------------------------

				// Set up mail headers.
				string from = username;
				string fromName = username;	// Or place human-readable name here.
				string to = "FRIEND@FRIEND.COM";
				string subject = "HttpMail Test";
				
				// Set up mail body.
				string body = null;
				body += "\n";
				body += "Hi There\n";
				body += "\n";
				body += "If you are reading this, then a HttpMail has been sent\n";
				body += "via Hotmail, using C# and the .NET framework.\n";
				body += "\n";
				body += "Congratulations!\n";
				body += "\n";

				// Now trying sending mail.
				Console.WriteLine("----------------- TEST SENDING ------------------");
				mailClient.SendMail(from, fromName, to, subject, body);
				Console.WriteLine("-------------------------------------------------");
			}

			// Catch exceptions.
			catch(Exception exception)
			{
				// Dump the exception.
				Console.WriteLine(exception);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions