14 December 2010

SPUtility.SendMail and the 2048 Character Limit

We were in the middle of testing a web part responsible for gathering information from visitors to our Client’s website and emailing it to someone responsible for responding to the request.  During testing, however, it was brought to our attention that the message was cutting off at 2048 characters.  Now, 2048 is one of those numbers that is usually indicative of some computational limit, but I was hopeful that Microsoft had thought through the possibility of emailing more than 2048 characters from SharePoint.  Luckily I was right. and wrong.

As it turns out, SPUtility.SendMail is not limited to any specific character limit as far as I can tell.  However, each LINE of text that you send via SendMail cannot exceed 2048 characters.  Since we were sending an HTML email it was constructed entirely without line breaks, far exceeding the 2048 character limit and ultimately helping to educate me about this obscure technical limitation whose only benefit thus far is offering me something to rant about on my blog. 

The fix is simple, just put in a carriage return and a line break often enough to avoid going past the 2048 character limit. 

I’m sure someone can present a great technical reason for the 2048 character limit, but it seems fairly arbitrary since the “rn” that got appended to the string are ultimately just characters too.

Keep up to date with Simple-Talk

For more articles like this delivered fortnightly, sign up to the Simple-Talk newsletter

This post has been viewed 2376 times – thanks for reading.

  • Rate
    [Total: 0    Average: 0/5]
  • Share

Damon Armstrong

Damon Armstrong is a Senior Engineering Team Lead with GimmalSoft in Dallas, Texas, and author of Pro ASP.NET 2.0 Website Programming. He specializes in Microsoft technologies with a focus on SharePoint and ASP.NET. When not staying up all night coding, he can be found playing disc golf, softball, working on something for Carrollton Young Life, or recovering from staying up all night coding.

View all articles by Damon Armstrong