Question

I am currently using this code in C# to email a file to my hotmail address with an attachment. I ran this and it worked great when attaching a 800KB file, but when I try to attach a 12MB file it just won't do it, I put it in a try catch but there were no exceptions, like it just skipped it. The email attachment size limit for hotmail is 25MB, would this affect the email code, or is there a separate limit when doing it through code? Thanks.

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
mail.From = new MailAddress("email@hotmail.co.uk");
mail.To.Add("receiving@hotmail.co.uk");
mail.Subject = "Emailed from C#";
mail.Body = "Emailed with attachment";
Attachment attachment;
attachment = new Attachment(@"C:\file.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new NetworkCredential("email@hotmail.co.uk", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top