narasiman rao

narasiman rao

  • NA
  • 519
  • 771.8k

i am sending excel file to my mail

Aug 25 2016 9:50 AM
 
 My code as follows
 
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(@"C:\Users\551386\Desktop\DataDump\Excel.xls");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("raj@gmailcom","12345");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
 
when i  execute the above code shows error as follows 
  Failure sending mail 
the above error shows in below line as follows 
  SmtpServer.Send(mail);
  please help me what is the mistake in my above code.  
 

Answers (1)