Send Email in Asp.Net C#.Net

This C#.net tutorial, we will discuss, how to send email in asp.net using C#.Net. Also, we will discuss how to send email using Gmail in asp.net.

Asp.Net provides System.Net.Mail namespace to send email in asp.net. So first add the namespace to the page.

using System.Net.Mail

Send Email in Asp.net using C#.Net

Below is the code to send email in asp.net using c#.net.

MailMessage message = new MailMessage();
message.From = new MailAddress(fromAddress@aspdotnethelp.com, "AspDotNetHelp.com");
message.To.Add(new MailAddress(toAddress@aspdotnethelp.com));
message.Subject = "This is mail Subject";
message.Body = "This is the email body !!!";
message.Priority = MailPriority.Normal;
SmtpClient emailClient = new SmtpClient();
emailClient.Host = "smtp host address";
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential
("networkcredentialid@aspdotnethelp.com", "password");
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
message.IsBodyHtml = true;
emailClient.Send(message);

Send Email in Asp.net using Gmail

Below is the code to send email using Gmail in asp.net.

MailMessage message = new MailMessage();
message.From = new MailAddress(Your gamil id, "Friendly disaplay name");
message.To.Add(new MailAddress(toAddress@aspdotnethelp.com));
message.Subject = "This is mail Subject";
message.Body = "This is the email body !!!";
message.Priority = MailPriority.Normal;
SmtpClient emailClient = new SmtpClient();
emailClient.Host = "smtp.gmail.com";
emailClient.Port = 587;
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("your gmail address", "your gmail password");
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
message.IsBodyHtml = true;
emailClient.Send(message);

You may like following .net tutorials:

This tutorial, we learned how to send email using C#.net and Gmail in asp.net.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>