Saturday, March 5, 2011

"Failure sending mail" error message when you send an email message by using a .NET Framework 4.0-based application that uses the "System.Net.Mail.SmtpClient" class if the email attachment is larger than 3 MB

I recently had an issue after upgrading a website from .Net 3.5 to .Net 4.0, particularly when trying to send an email attachment larger than 3 MB using the System.Net.Mail.SmtpClient class.

Failure sending mail.

Index was outside the bounds of the array.

System.IndexOutOfRangeException stack trace:
at System.Net.Base64Stream.EncodeBytes(Byte[] buffer, Int32 offset, Int32 count, Boolean dontDeferFinalBytes, Boolean shouldAppendSpaceToCRLF) at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mime.MimePart.Send(BaseWriter writer) at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer) at System.Net.Mail.SmtpClient.Send(MailMessage message)

Turns out this was a known bug with a hotfix already available:

Some other articles I found along the way: