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
try
{
MailMessage msg = new MailMessage();
//Below loop add multiple Recipient mail id example
for (int i = 0; i <= toId.Length - 1; i++)
{
msg.To.Add(toId[i].ToString());
}
MailAddress frmAdd = new MailAddress(frmgmail);
msg.From = frmAdd;
//Check user enter CC address or not
if (ccId != "")
{
msg.CC.Add(ccId);
}
//Check user enter BCC address or not
if (bccId != "")
{
msg.Bcc.Add(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("smtp.gmail.com", 587);
NetworkCredential NetCrd = new NetworkCredential(frmgmail, frmpwd);
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Send(msg);
clear();
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("smtp.mail.yahoo.com", 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#
Conclusion:
I hope my article help to beginner for send email using ASP.Net.