--><!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (
Sending Email through ASP. NET
Common and important aspect used in Web designing is email sending. Basic use of sending email from a Web page is to enable the users to give their comments/suggestions through web form. The .NET Framework provides extremely straightforward means to send emails. ASP .NET makes use of SmtpMail and MailMessage classes to send an emaill. The SmtpMail and MailMessage classes are defined in the System.Web.Mail namespace. The MailMessage class has properties and methods for creating an email and the SmtpMail class has send method to send an email.
Just copy and paste the following code to send an email
public int sendMail(string to,string cc,string bcc,string subject,string body)
MailMessage msg = new MailMessage();
msg.From = "your_email_id";
msg.To = to;
msg.Cc = cc;
msg.Bcc = bcc;
msg.Subject = subject;
msg.Body = body;
on button click
private void Button1_ServerClick(object sender, System.EventArgs e)
String to = “to_email_id”;
String cc = “cc_email_id”;
String bcc = “bcc_email_id”;
String subject = “your subject goes here”;
String body = “your body text goes here”;
int status = sendMail(to,cc,bcc,subject,body);
if(status == 1)
Response.Write("your mail has been sent successfully");
Response.Write("sorry! your mail could not be sent”);
How to send attachments?
The MailMessage not only provide methods and properties to create mail but also to attach files (attachments). The following line can be included in the above program to send attachments.
Mahantesh Hongal is MCA grad from Karnatak University Dharwad (Karnataka, India). He learned a whole lot from internet community and He would like to contribute back just by posting the useful stuffs for the internet community. He has started his programming career from BASIC programming language and until now He has learned a bit about Pascal, dBase, FoxPro, Cobol, vb, c, c++, c#, java, Perl and asp .net.