How to send E-mail from application

There are so many way to send E-mail from ASP.NET webpage to any given particular email address, but most common way and most frequently used way to sent email from webpage by using SMTP. So here below Article Described you the Steps to send an Email from your ASP.NET webpage

There is a simply 3 Step process to sent an email from webpage to the Given E-mail ID. All 3 step to sent an email from webpage to Email id is given below

Step 1 : Configure your web.config file in Mailsettings Section


Step-2 Define below Namespace in your code behind file

using System.Net;
using System.Net.Mail;

Step- 3 On button Click Right below code to sent an email

protected void btnSend_Click(object sender, EventArgs e)
string toEmailID = "";
string mailId = "";
string bodyMsg = "Test Email";
string subject = "TEST";
MailMessage mail = new MailMessage();
mail.From = new MailAddress(mailId);
mail.Subject = subject;
mail.Body = bodyMsg;
mail.Cc = "";
mail.Bcc = "";
mail.IsBodyHtml = true;
//Attach file using FileUpload Control and put the file in memory stream
if (FileUpload1.HasFile)
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream , FileUpload1.FileName));

SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
lblmsg.Text = "Your E-mail is sent sucessfully";
Catch(Exception ex)
Throw ex;
finally {}


Author: Nandhini15 Jan 2012 Member Level: Gold   Points : 1

Few Comments:

You can add CC Address, BCC Address, Attachment, Attachment as zip etc.,.

Then it will include complete code with all the mail options.

The Basic functionality of sending mail looks very Good and useful to the beginers

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: