using System.Net.Mail;
using System.Net;
protected void btnSent_Click(object sender, EventArgs e)
{
string toEmailAddress="xx@gmail.com";
string GmailId="abc@gmail.com";
string password="";
string bodyMsg="helo its testing mail";
MailMessage mail = new MailMessage();
mail.To.Add(toEmailAddress);
mail.From = new MailAddress(GmailId);
mail.Subject = txtSubject.Text;
mail.Body = bodyMsg;
mail.IsBodyHtml = true;
//Attach file using FileUpload Control and put the file in memory stream
if (FileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
smtp.Send(mail);
}