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
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

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?