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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

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

 Subscribe to Code Snippets

Sending Mail with attachment from C# using Gmail SMTP Client

Posted By:Krishna       Posted Date: April 12, 2012    Points: 40    Category: Email    URL: http://www.dotnetspark.com  

Hi here i want to explain you how to send mail with attachment using C# class with Gmail SMPT client. we can use using System.Net.Mail; name space which contains list of class like SmtpClient,MailAddressCollection,MailMessage and Attachement used for sending mail in C# code.

public void sendMail()


          SmtpClient _SmtpClient = new SmtpClient("smtp.gmail.com");

                MailAddressCollection _MailAddressCollection = new MailAddressCollection();

                MailMessage _message = new MailMessage();

                _message.From = new MailAddress("muralikrishna.surap@gmail.com");

                _message.Body = "Body of the mail";

                _message.Subject = "Sending mail from c# Code";


                Attachment data = new Attachment("D:\\Attachement.xls");


                _SmtpClient.Port = 587;

                _SmtpClient.Credentials = new System.Net.NetworkCredential("muralikrishna.surap@gmail.com", "*****");

                _SmtpClient.EnableSsl = true;




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