Blog

Send email using C#

We are going to use Gmail outgoing mail server in our code here to demonstrate how you can send an email from your application using C#

SmtpClient oSmtpClient = new SmtpClient();
oSmtpClient.Host = "smtp.gmail.com"; //The Outgoing mail server
oSmtpClient.Credentials = new NetworkCredential("Your Email", "Your password");
oSmtpClient.Port = 587;
oSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
oSmtpClient.EnableSsl = true;
MailMessage msg = new MailMessage("Email From", "Email To");
msg.Subject = "Subject goes here";
msg.Body = "Body goes here";
oSmtpClient.Send(msg);

Share this post



Leave a comment


Previous Post

Next Post


\