Home > Code > C# > Mail Sending using Gmail SMTP Client

Mail Sending using Gmail SMTP Client

by Murali Krishna.S   on Jul 15, 2013   Category: C#   |  Views: 1516    |  Points: 25   |  Starter 


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";
_message.To.Add("muralikrishna.surap@gmail.com,1234@gmail.com");
Attachment data = new Attachment("D:\\Attachement.xls");
_message.Attachments.Add(data);
_SmtpClient.Port = 587;
_SmtpClient.Credentials = new System.Net.NetworkCredential("muralikrishna.surap@gmail.com", "*****");
_SmtpClient.EnableSsl = true;
_SmtpClient.Send(_message);
}




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts