Click here to Skip to main content
13,507,789 members
Click here to Skip to main content
Add your own
alternative version


67 bookmarked
Posted 21 Dec 2005

Windows Email Client application using .NET (C#)

, 21 Dec 2005
Rate this:
Please Sign up or sign in to vote.
An article on a Windows email client application using .NET.

Sample Image

Sample Image


This article is to show the reader how easy it is to send an email using the .NET framework. Not only can the user determine the format of the email (HTML or text), non-ASCII characters can also be sent with relatively simple coding. A Windows email client application along with the source code can be found in this article.

Configuring a PC to use the application

Some configuration needs to be done before you can make use of the application.

  1. IIS needs to be installed. You can install it by clicking the Internet Information Service check box in ‘Control Panel’->‘Add/Remove Windows Components’. Also, make sure the SMTP Service check box is checked in the IIS details.
  2. In Administrative tools -> Internet Information Services, right click on 'SMTP Virtual Server' and select Properties in the context menu. Make sure the IP address points to the local host ( or is set to (Unassigned).

    Sample Image

  3. Under the Access tab, click on the Relay button and check on the box “All except the list below”.

    Sample Image

  4. Under the Message tab, you will find the directory where all the bad mails are stored.

    Sample Image

Using the code

In order to make use of the mail services from .NET, you need to have a reference to System.Web in your solution explorer. This reference is added to the ASP.NET application by default but is not present when you create a Windows application.

First, you need to create a MailMessage object:

MailMessage mm = new MailMessage();

Next, you need to set the members of the MailMessage object you created:

//Setting the fields of the emails
mm.To = toText.Text;
mm.From = fromText.Text;
mm.Cc = ccText.Text;
mm.Bcc = bccText.Text;
mm.Subject = subjectText.Text;

//The body of the message text
mm.Body = messageText.Text;

//The Priority of the mail
switch (settingDialog.PrEnum)
    case Priorities.High:
        mm.Priority = MailPriority.High;
    case Priorities.Normal:
        mm.Priority = MailPriority.Normal;
    case Priorities.Low:
        mm.Priority = MailPriority.Low;

//The encoding format of the mail
switch (settingDialog.EdEnum)
    case Encodings.ASCII:
        mm.BodyEncoding =Encoding.ASCII;
    case Encodings.Unicode:
        mm.BodyEncoding =Encoding.Unicode;
    case Encodings.UTF7:
        mm.BodyEncoding =Encoding.UTF7;
    case Encodings.UTF8:
        mm.BodyEncoding =Encoding.UTF8;

//Format of mail is in HTML format
mm.BodyFormat = MailFormat.Html;

if (!attachText.Text.Equals("")) 
    //adding attachments. 
    //You can add multiple attachments if you want
    MailAttachment ma = new MailAttachment(attachText.Text);
    if (ma != null) 

To send the mail, make use of the Send method:


As you can see, to send a mail with .NET is really that simple.

Known Issues

  1. When I set the priority to high, Outlook Express still shows it as a normal priority mail.

    This is a known issue with .NET. The priority will work with Microsoft Outlook but not with Outlook Express.


  1. An exception is thrown: "Could not access 'CDO.Message' object'"

    Make sure you follow point #2 in the section “Configuring the PC” above.

  2. Mail cannot be sent.

    Make sure you are not behind any firewall that disrupts the sending of the mail. Make sure your port 25 is not blocked. You can check if there are any bad mails or mails under queue in your mailroot directory. Usually, this folder can be found in “C:\Inetpub\mailroot”.

  3. After disabling the firewall, my email still failed to be sent.

    Make sure there isn’t any mail under the queue in your mailroot directory. You may also want to make sure that the string in “SmtpMail.SmtpServer” is referring to the localhost.

  4. Email sent with Unicode encoding cannot be received.

    You may want to use UTF8 encoding instead. Check if the email is being stored in the queue folder in your mailroot directory. You may want to open the .eml attachment to see if the Unicode message is being encoded correctly.


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


About the Author

Fabian Tang
Singapore Singapore
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionTkx Pin
Sameera Fonseka4-Jan-12 6:03
memberSameera Fonseka4-Jan-12 6:03 
GeneralMy vote of 5 Pin
jmnemonik20-Jan-11 22:26
memberjmnemonik20-Jan-11 22:26 
Generalhi Pin
sivakumarmr1024-Jul-10 5:48
membersivakumarmr1024-Jul-10 5:48 
Generalthank you Pin
saenthil21-Apr-10 22:58
membersaenthil21-Apr-10 22:58 
GeneralThank you Pin
o3yoon10-Apr-09 18:54
membero3yoon10-Apr-09 18:54 
Generalmy email always getting in the queue folder Pin
nagada77714-Mar-09 1:01
membernagada77714-Mar-09 1:01 
QuestionHow to send and receive a mail in LAN Pin
smraj150316-Nov-08 23:51
membersmraj150316-Nov-08 23:51 
AnswerRe: How to send and receive a mail in LAN Pin
abid00713-Sep-12 22:34
memberabid00713-Sep-12 22:34 
AnswerRe: How to send and receive a mail in LAN Pin
abid00713-Sep-12 22:35
memberabid00713-Sep-12 22:35 
GeneralRegrding Anonmymous mail demo Pin
rajkumari9-Jun-08 23:57
memberrajkumari9-Jun-08 23:57 
General[COMException (0x80040213): The transport failed to connect to the server. Pin
Paul's19-Nov-07 6:58
memberPaul's19-Nov-07 6:58 
Generalproblem in using "" Pin
EEmaan30-Jan-07 20:29
memberEEmaan30-Jan-07 20:29 
GeneralSecurity Risks R Us Pin
Rich Bryant22-Dec-05 3:45
memberRich Bryant22-Dec-05 3:45 
GeneralRe: Security Risks R Us Pin
Vertyg022-Dec-05 9:19
memberVertyg022-Dec-05 9:19 
GeneralRe: Security Risks R Us Pin
miguelguzman27-Dec-05 2:34
membermiguelguzman27-Dec-05 2:34 
GeneralRe: Security Risks R Us Pin
Mufaka27-Dec-05 14:09
memberMufaka27-Dec-05 14:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180417.1 | Last Updated 21 Dec 2005
Article Copyright 2005 by Fabian Tang
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid