Posted in WIN_7

Send Email from GMail, Yahoo! And Hotmail Using C# in ASP.Net and WCF


Send Email from GMail, Yahoo! And Hotmail Using C# in ASP.Net and WCF

In this article we are going to see how to send email using C#.

Most of the applications we need to send mail to the user here I am going to explain how you will send mail using your Gmail, Yahoo and Hotmail account.

For sending mail we need the server details like smtp host name and port to configure SMTP.  See the list of server details for sending mail.

Name Host name Port
Gmail 587
Yahoo! 587
Hotmail 587

Create new or WCF application according to your requirement. Then go to your code behind page and write the following code for example using Gmail.

public void SendEmail()




SmtpClient clientSMTP = new SmtpClient(“”, 587);


clientSMTP.EnableSsl = true;

clientSMTP.DeliveryMethod = SmtpDeliveryMethod.Network;

clientSMTP.UseDefaultCredentials = false;

clientSMTP.Credentials = new NetworkCredential(“”,”password”);

using (MailMessage message = new MailMessage())


message.From = new MailAddress(“yourgmailid”);

message.Subject = “Subject”;

message.IsBodyHtml = true;


message.Body=”Hi ” + “Suresh” + “!\n” +

“Welcome to C# Corner!” +

“Please <a href='” + ” ” + “‘>click</a> here to activate your account. \nThanks!”;




catch(Exception ex)








You can send email with attachment also using Attachment property. If you need to CC to someone or BC to someone use the following code







Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s