C# Sending Email with SSL 465 or 587

last edited on: 19-Jan-2018; tagged: c#,smtp

Here is a real word example of sending email with SSL port 465 or 587 using C# programming language. In the example we are using GMAIL smtp server details. This is a very easy process to send a single email like after user registration or forget password etc.

using System.Net.Mail;
MailMessage mail = new MailMessage();
String FromEmail = yourEmail@example.com;
String ToEmail = to@example.com         
mail.From = new MailAddress(FromEmail, "From Name");
mail.Subject = “Your Subject”;
string replytoEmail = “reply@example.com”;
mail.Headers.Add("Reply-To", replytoEmail);
mail.Body = “Body of the Email”;
mail.IsBodyHtml = true; // setting true if the email is in HTML format
mail.To.Add(new MailAddress(ToEmail));
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; // 465 or 587
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("username", "password");// Your gmail user name and password
smtp.Host = "smtp.gmail.com";// SMTP server


ASP.NET (C#) Sending Bulk Email

tagged: c#,smtp

C# DataTable

tagged: c#,datatable