Email Sending in c# using Gmail SMTP server
Sending Email in c# using G mail Server
SmtpClient emailClient = new SmtpClient();
MailMessage Mail = new MailMessage();
MailMessage Mail = new MailMessage();
//You need to add at least one recipient
Mail.To.Add("To");
Mail.To.Add("To");
// Do you sending the body in HTML format
Mail.IsBodyHtml = true;
Mail.IsBodyHtml = true;
//Specify the sender of mail
Mail.From = new MailAddress(FromEmail, OriginatorName);
Mail.From = new MailAddress(FromEmail, OriginatorName);
// specify sender sender email and sender name
Mail.Sender = new MailAddress(FromEmail, OriginatorName);
Mail.Sender = new MailAddress(FromEmail, OriginatorName);
// Set Mail Priority to High, Normal
Mail.Priority = MailPriority.Normal;
// specify the subject of mail
Mail.Subject = "This is my first email in c# using g mail smtp server";
Mail.Subject = "This is my first email in c# using g mail smtp server";
// specify the HTML body
Mail.Body = "<h1>Hi this is body of email</h1>";
Mail.Body = "<h1>Hi this is body of email</h1>";
// specify the Gmail smtp server, smtp.gmail.com is the g mail smtp server
emailClient.Host = "smtp.gmail.com";
emailClient.Host = "smtp.gmail.com";
//Specify your email and password to connect to your g mail account to send the mail
emailClient.Credentials = new System.Net.NetworkCredential("Your Gmail ID", "Your Gmail Password");
//Default Post for Gmail Smtp server is 587
emailClient.Port = 587;
//Do you want to ssl to be enabled
emailClient.EnableSsl = true;
emailClient.EnableSsl = true;
//Finally send the mail
emailClient.Send(Mail);
Mail.Dispose();
emailClient.Send(Mail);
Mail.Dispose();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Please put your comment that how you liked this explanation of email sending using g mail server
///////////////////////////////////////////////////////////////////////////////////////////////////////////
do I need to include any extra reference or namespaces?
ReplyDelete