Send email using C#

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 Reply

Your email address will not be published. Required fields are marked *