SPUtility.SendMail and the 2048 Character LimitPublished 14 December 2010 3:02 am
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.