Home > development, error, event handlers, MOSS, MS SharePoint Sever, sharepoint, sps > SPUtility.SendEmail Limitation

SPUtility.SendEmail Limitation

SPUtility.SendMail has a limit on the number of characters in one line. There is no restriction on the overall number of characters. One line should not exceed 2048 characters.

So, a simple thing is to break your string (htmlBody) in chunks of 2048 or less characters in one line. You can use a string function Substring(int start index, int length) to break your string into small chunks, use a for loop or anything you like. The important thing is how to break the string. It’s by appending “\n” after each chunk. This works for me and should work for you.

Example:

htmlBody = htmlBody + "\n" + myNewChunk + "\n"; //something like this.

Below is what works for me, its the original piece of code, only thing concerns you is the placement of “\n” within the string (try different combinations, it can frustrate you a little before it works):

htmlBody = "\n" + htmlBody.Replace(EmailTemplateTokens.AllEmployees, "<p>" + replacementString + "\n" + EmailTemplateTokens.AllEmployees);

Hope this helps–
Rehman.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: