Tools Used Visual C# .NET
Namespace System.Web.Util
Assembly System.Web.dll
The SmtpMail class can be used to send from your C# application. Mail is by default queued on the system, ensuring that the calling program does not block network traffic. The SmtpMail class is defined in the namespace System.Web.Util. You need to call
using System.Web.Util
before you use SmtpMail. This class has only one member function Send. Send sends a mail message. The Send method is overloaded. Either a MailMessage class or four arguments can be passed to the Send message. You can call the Send method in two manners:
SmtpMail.Send(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMessage.Text);
Or, if you don't want to call System.Web.Util.
System.Web.Util.Smptmail.Send(txtFrom.Text, txtTo.Text, txtSubject.Text, txtMessage.Text);
You can call the Send method in two ways.
1. By passing MailMessage as a parameter
public static void Send(MailMessage);
Here MailMessage is a class.
MailMessage mailMsg = new MailMessage();
mailMsg .From = "[email protected]";
mailMsg .To = "[email protected]";
mailMsg .Cc = "[email protected]"";
mailMsg .Bcc = "[email protected]";
mailMsg .Subject = "SubjectOfTheMailString";
mailMsg .Body = "BodyOfTheMailString";
SmtpMail.Send(mailMsg );
2. Direct method.
public static void Send(string from , string to, string subject, string messageText);
Parameters
Description
from
Email address of sender
to
Email address of recipient
subject
Email subject line
messageText
Body of Email message
Example:
SmtpMail.Send("[email protected]", "[email protected]", "Subject", "Message body");
The MailMessage Class
The MailMessage class can be used to send mails with cc, bcc or attachments. The MailMessage constructor initializes a new instance of the MailMessage class. It doesn't take any parameters.
MailMessage mail = new MailMessage();
Members
Description
Bcc
Specifies a semicolon-separated list of email addresses that will receive a private copy of the email message.
Body
Indicates the body content of the email message.
BodyEncoding
Indicates the encoding type of the email message.
BodyFormat
Indicates the type of the email message body (text or html).
Cc
Specifies a semicolon-separated list of email addresses that will receive a copy of the email message.
From
Indicates the email address of sender.
Priority
Indicates the priority of the email message.
Subject
Indicates the subject line of the email.
To
Indicates the email address of the recipient.
UrlContentBase
Indicates the base of all relative URLs used within an HTML-encoded message.
Attachments
List of MailAttachments to be transmitted with the message. This property is read-only.
Headers
Indicates the dictionary of custom headers to be transmitted with the message. This property is read-only.
Each member of this class are pretty easy to understand. Say you want to send an attachment with the mail. You use Attachment member to attach the mail. Say I want to attach mcb.jpg with the mail.
mail.Attachments.Add(new MailAttachment(@"C:\mcb.jpg"));
Each member of this class are pretty easy to understand. Say you want to send an attachment with the mail. You use Attachment member to attach the mail.
Other MailMessage members have been used in the above example.

arun yegiPosted Aug 22, 2011, 6:50 AM
how to send a text msg to mobile in c#?
madhu krishnaPosted Feb 25, 2010, 12:08 AM
the code which u hav given as example it is not working.. when i am trying to send mail. it is not sent a mail..? wat is d prblm?
rizwan bashireditedPosted Mar 27, 2009, 10:00 AMEdited Mar 27, 2009, 10:04 AM
hi you have done god job , can u make it with system.net.mail if u can. but thanks for this post.
Sarla SankarPosted Feb 20, 2008, 1:21 AM
I follow your example.it is working fine. How can i set Attaching file is Optional. i wrote one example in that, if i attach file the application is working fine. if i didn't attach file it says an error: Invalid Attachment. what i have to change. Thanx in advance
Nguyen Duc HoaPosted Jun 3, 2007, 12:13 PM
I've used all methods in this article, but the mail hasn't sent to my Tomail. How much time from I click the button Send, the mail will be come to my inbox?