Before using this code you need add following namespace
using System.Net;
using System.Net.Mail;
You just copy paste the following code in your program.
public int SendEmail(string sFromEmail, string sHeader, string query)
{
string sToEmail;
bool fSSL = true;
try
{
//Creating Message object
System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
if (fSSL)
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]");

Join the conversation! Your thoughts help the community grow.