.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Email >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Send Email to gmail account

Posted By:abhays       Posted Date: March 25, 2014    Points: 40    Category: Email    URL: http://www.dotnetspark.com  

Below code snippent explains how to send email to gmail account

protected string SendEmail(string toAddress, string subject, string body)
     string result = "Message Sent Successfully..!!";
     string senderID = "SenderEmailID";// use sender's email id here..
     const string senderPassword = "Password"; // sender password here...
       SmtpClient smtp = new SmtpClient
         Host = "smtp.gmail.com", // smtp server address here...
         Port = 587,
         EnableSsl = true,
         DeliveryMethod = SmtpDeliveryMethod.Network,
         Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
         Timeout = 30000,
       MailMessage message = new MailMessage(senderID, toAddress, subject, body);
     catch (Exception ex)
       result = "Error sending email.!!!";
     return result;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend