Wednesday, April 23, 2014

ASP.NET MVC Mail Sending with attachment file

You can send mail with attach file using the code



 MailMessage mail = new MailMessage();  
       SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
       mail.From = new MailAddress("atiour.islam@gmail.com");  
       mail.To.Add("atik.kotha@gmail.com");  
       mail.Subject = "Test";  
       mail.Body = "Hi";  
       System.Net.Mail.Attachment attachment;  
       attachment = new System.Net.Mail.Attachment("D:\\ff.pdf");  
       mail.Attachments.Add(attachment);  
       SmtpServer.Port = 587;  
       SmtpServer.Credentials = new System.Net.NetworkCredential("atiour.islam@gmail.com", "password");  
       SmtpServer.EnableSsl = true;  
       SmtpServer.Timeout = 60000;  
       SmtpServer.Send(mail);   


Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file

In my Xamarin form application their was dependency Restclient on Microsoft.Bcl.Build Microsoft.Bcl. i just remove all using nuget and ...