|
// 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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.