Sending Email Using SMTP Client In .NET

Almost all applications that you build will require some sort of notification sending mechanism. Most of the times the notification is sent as an email to the user. In this post, you can learn about how you can quickly get a module to send Emails for applications that are developed in .NET platform.

The code is written in C# which uses a configured SMTP client to send emails.


public void SendEmail(string toEmail, string subject, string messageBody)
 System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); 
 message.Subject = subject;
 message.Body = messageBody;


System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

This method takes receiver’s email, mail subject and message body as parameters and email is sent using the SMTP client.

The SMTP client is configured in web.config file as below:

 <smtp from="[email protected]">
 <network host="" 
 userName="[email protected]" 
 enableSsl="false" />


READ  Tips To Keep In Mind Before Attending Your Next Tech Workshop