How to send email using ASP.NET ?

In this article I have explained about how to send email using ASP.Net. This example code also explained how to send email with attachment, bcc, cc and multiple recipient options. The email sends with help of SMTP.

How to send email from gmail using ASP.NET?
Sending mail from ASP.NET website with help of SMTP

MailMessage msg = new MailMessage();
//Below loop add multiple Recipient mail id example
for (int i = 0; i <= toId.Length - 1; i++)
MailAddress frmAdd = new MailAddress(frmgmail);
msg.From = frmAdd;
//Check user enter CC address or not
if (ccId != "")
//Check user enter BCC address or not
if (bccId != "")
msg.Subject = msgsubject;
//Check for attachment is there
if (FileUpload1.HasFile)
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
msg.IsBodyHtml = true;
msg.Body = mailContent;
SmtpClient mailClient = new SmtpClient("", 587);
NetworkCredential NetCrd = new NetworkCredential(frmgmail, frmpwd);
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
Label1.Text = "Mail Sent Successfully";
catch (Exception ex)
Label1.Text = "Unable to send Mail Please try again later";

How to send email from yahoo using ASP.NET?
You can send email from yahoo id is same like gmail but you can change SMTP details and port number

//use this line for sending mail from yahoo
SmtpClient mailClient = new SmtpClient("", 25);
//Change Ssl false
mailClient.EnableSsl = false;
//For more detail download source and execute

Source Code Detail:
Here with I have attached source code for sending mail from yahoo or gmail. Download it and try to send mail using ASP.Net website.
Front End : ASP.NET
Code Behind : C#

I hope my article help to beginner for send email using ASP.Net.


  • Send_email (42951-12032-Mail_send_Gmail_Yahoo.rar)
  • Comments

    No responses found. Be the first to comment...

  • 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: