I have been trying to send a big attachment (9 MB) using C# ASP.NET 3.5 System.Net.Mail. I read that .NET 4.0 had a bug which doesn't allow this, but .NET 3.5 is fine. .NET 4.0 Fails When sending emails with attachments larger than 3MB
Since .NET 3.5 doesn't close the session properly after an email is sent, I added this line before it's sent:
smtpClient.ServicePoint.MaxIdleTime = 2;
The line
smtpClient.Send(email);
is still throwing this error:
Exceeded storage allocation. The server response was: 5.3.4 Error: message file too big:
at System.Net.Mail.DataStopCommand.CheckResponse(SmtpStatusCode statusCode, String serverResponse)
at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn)
at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args)
at System.Net.ClosableStream.Close()
at System.Net.Mail.MailWriter.Close()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Changing the encoding doesn't help. This corrupts the attachment:
email.Attachments[0].TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
Could someone please help? Thank you.