SMTP Mailing Application

Introduction

This is an article on how to use the Mail Components in .NET to create a simple application to send e-mail. 

Figure 1 - The Smtp Mailing Application

The Smtp Mail functionality is contained in the System.Web.Mail namespace and contains three classes:

Table 1 - System.Web.Mail Namespace

System.Web.Mail Classes Description
SmtpMail Class used to send Mail via Windows 2000 SMTP services
MailMessage This class contains everything contained in an e-mail message. An instance of this can be sent by the SmtpMail class
MailAttachment This is a class representing an attachement to an email.

The SmtpMail Class gives you two static methods to send mail: the quick and easy way, and the more detailed way.

SmtpMail.Send(FromString, ToString, SubjectString, MessageString)

or

SmtpMail.Send(aMailMessage)

I opted to send email using the MailMessage object in this example because you can send a lot more information.  Some of the properties of the MailMessage Object are shown below:

MailMessage Property

Description

From who the email is from
To who the email is to
Cc who the email is copied to
Bcc who the email is copied to without seeing the recipients
Attachments A collection of Attachments to the email
Subject Subject of the email
Body Message Body of the email
BodyFormat The format of the Message Body (Currently Text or Html)
Priority MailPriority of the Message (High, Low, or Normal)

Table 2 - MailMessage Properties for an E-mail Message

You might also like...

Comments

About the author

Mike Gold United States

Mike Gold is President of Microgold Software Inc. and Creator of WithClass 2000 a UML Design Tool for C#. In the last few years Mike has consulted for companies such as Merrill Lynch and Chase M...

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.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan