Custom SMTP in C#

Demonstration

To send an SMTP message, you simply instantiate an instance of the class, set the appropriate data members and call the Send method.

static void Main( string[] args)
{
    try
    {
        kbcafe.Smtp smtp = new kbcafe.Smtp();
        smtp.server = "smtp.xxx.com";
        smtp.from = "[email protected] (zzz)";
        smtp.subject = "Hello World";
        smtp.bodyHtml = "<HTML><BODY>Hello World</BODY></HTML>";
        smtp.to.Add("[email protected]");
        smtp.Send();
    }
    catch( kbcafe.SmtpException e)
    {
        System.Console.WriteLine("{ 0}", e.What());
    }
}

If you reuse this code, replace the xxx, yyy and zzz parameters by valid values. A valid from address may be "[email protected] (Joe Bloggs)".

You might also like...

Comments

About the author

Randy Charles Morin

Randy Charles Morin Canada

Randy's article are Copyright 1998-2003 Randy Charles Morin

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perl - The only language that looks the same before and after RSA encryption.” - Keith Bostic