Fix for Community Server Contact Form Email Line Break Constipation

Since upgrading to CS2007.1 my Contact Form line breaks no longer existed.  Do yours?  There were some threads about it on CS Forums.  I reported on them and even applied the patch (updating Globals.cs NewLine constant), but no go in Vermont.  So I took a deeper look into the flow of a text message from my site’s contact form to my Outlook inbox and here’s the fix I came up with.  There may be another fix of which I’m unaware, or maybe there was never a problem in the first place, but all I know is that I now have HTML formatted contact form email with line breaks and everything.  I received a site email this morning, about my blog list popup mod, and it was sweet to see line breaks again.

So the comment text flows straight from the Contact Form’s Chameleon ContactForm class in CS.Blogs to the CS.MailRoom.CommonEmailProvider.QueueContactRequest() method.  The text at that point contains \r\n’s as line break characters from the textbox ASPNET control.  The CS EmailTemplateProvider contains two static methods, FormatPlainHtmlAsText and FormatPlainTextAsHtml which do a lot of the Regex-to-Unicode work, and are very cool in what they do, but we can’t get there from here, as the two methods are protected within the provider class.  But our requirements are the same: regex in, HTML out. 

The changes I made in the CS.MailRoom.CommonEmails.QueueContactRequest() method are in bold below.


body = Regex.Replace(body, “\n”, “<br />”,
    RegexOptions.IgnoreCase | RegexOptions.Compiled);
body = body.Replace(“\r”, string.Empty);

tokens.Add(new EmailTextToken(“AppTitle”, appName));
tokens.Add(new EmailTextToken(“Body”, body));

tokens.Add(new EmailTextToken(“Name”, submittedName));


email.From = new MailAddress(from);

email.IsBodyHtml = true;


That revitalizes the email body’s shapely figure, but there’s still the remaining <body /> area of the ContactForm Email Template in emails.xml.  The dashed line and “This email sent…” text.  That change is below where you’ll notice the HTML code around the areas of the template body.

Line breaks.  Didn’t know how much I’d miss’em.

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.