Email Sending in c# using Gmail SMTP server

          Sending Email in c# using G mail Server

                SmtpClient emailClient = new SmtpClient();
                MailMessage Mail = new MailMessage();
                 //You need to add at least one recipient
                Mail.To.Add("To");
                  
                 // Do you sending the body in HTML format
                Mail.IsBodyHtml = true;
                
                //Specify the sender of mail
                Mail.From = new MailAddress(FromEmail, OriginatorName);
                  
              // specify sender sender email and sender name
                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";

              // specify the HTML body
                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";

                //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;

               //Finally send the mail
                emailClient.Send(Mail);
                Mail.Dispose();


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Please put your comment that how you liked this explanation of email sending  using g mail server
///////////////////////////////////////////////////////////////////////////////////////////////////////////

Comments

  1. do I need to include any extra reference or namespaces?

    ReplyDelete

Post a Comment

Popular posts from this blog

Insert, Delete Rows, columns in HTML table Using Javascript

Lite PromiseJS(Light weight JavaScript promise library)

Open source Social Networking site in Asp.net and Microsoft Ajax