I wanted to write up a quick blog post related to DotNetNuke 5.4.4 and some issues / bugs that were created as a result of some changes to recent DNN updates within the email functions. First some background information... We started getting some reports from clients that that after they upgraded to DNN 5.4.4 they began having email issues... Specifically the CPU would max out after an email was sent within Dynamic Forms, Dynamic Registration etc...
For the most part the error they would see in the event log would be something like this:
System.Threading.
ThreadAbortException: Thread was being aborted. at System.AppDomain.GetId() at System.Threading.Thread.get_CurrentCulture() at Go1(RegexRunner ) at System.Text.RegularExpressions.CompiledRegexRunner.Go() at System.Text.RegularExpressions.RegexRunner.Scan(Regex regex, String text, Int32 textbeg, Int32 textend, Int32 textstart, Int32 prevlen, Boolean quick) at System.Text.RegularExpressions.Regex.Run(Boolean quick, Int32 prevlen, String input, Int32 beginning, Int32 length, Int32 startat) at System.Text.RegularExpressions.Regex.IsMatch(String input) at DotNetNuke.Common.Utilities.HtmlUtils.IsHtml(String text) at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Cc, String Bcc, String ReplyTo, MailPriority Priority, String Subject, MailFormat BodyFormat, Encoding BodyEncoding, String Body, List`1 Attachments, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword, Boolean SMTPEnableSSL)
Over the past few weeks we have shared some emails with some DNN Core Team Members as well as reviewed/updated several threads on dotnetnuke.com which ill reference below related to some further history on this issue.
Forum Threads
DotNetNuke Forum Thread Related to 5.4.4 with another vendors module (Onyak's Draconis)
DotNetNuke Forum Thread Related to 5.4.4 with core Newsletter module
DotNetNuke Forum Thread with Email Causing CPU to Hang - Fix could be to upgrade to .NET Framework 4.0?
DotNetNuke Forum Threads Related to 5.4.4 and Email Issues
DotNetNuke 5.5 - Might fix email issues?
Gemini References
http://support.dotnetnuke.com/issue/ViewIssue.aspx?ID=12826&PROJID=2
http://support.dotnetnuke.com/issue/ViewIssue.aspx?ID=12939&PROJID=2
So... where is this error coming from? From what I can tell some new code was added into either 4.3 or 4.4 under the mail.vb file and then HtmlUtils.vb file. This code changes to see if the email message is HTML by running a RegEx.Match check. A few areas of code this is in within 5.4.4 include mail.vb:
If HtmlUtils.IsHtml(Body) Then
Dim HTMLView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, Nothing, "text/html")
objMail.AlternateViews.Add(HTMLView)
End If
Which then calls this function within the HTMLUtils.vb file:
Public Shared Function IsHtml(ByVal text As String) As Boolean
If (String.IsNullOrEmpty(text)) Then
Return False
End If
Return True
Return HtmlDetectionRegex.IsMatch(text)
End Function
This runs a RegEx match from this code / regular expression.
Private Shared HtmlDetectionRegex As New Regex("^\s*<\w*(.*\s*)*\w?>\s*$", RegexOptions.Compiled Or RegexOptions.IgnoreCase)
So... At least for some environments and platforms this can cause your CPU to max out or at least cause the error above for the 'Thread was being aborted'.
The fix? Well with the most recent beta release of the 5.5 version I can still see the exact same code within the 5.5 code as exists within the 5.4.4 code. I did receive this email / comments from Shaun Walker directly though.
" In 5.5 we made a change so that the IsHtml function is NOT called if you pass in a BodyFormat parameter of MailFormat.Html…
Before:
'if body contains html, add html part
If HtmlUtils.IsHtml(Body) Then
Dim HTMLView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, Nothing, "text/html")
objMail.AlternateViews.Add(HTMLView)
End If
After:
'if body contains html, add html part
If objMail.IsBodyHtml Then
Dim HTMLView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, Nothing, "text/html")
objMail.AlternateViews.Add(HTMLView)
End If
"
So - It does appear that this will be fixed in the 5.5 release even if the code isn't the most recent code avaliable for the beta.
What about customers of ours or others running on 5.4.4 Community Edition and having this issue? We have created a separate build of the 5.4.4 version which basically will return true and treat the emails as HTML emails. We are testing this build and reviewing the code changes... Once its ready we will be able to provide it to customers (should be within the next two weeks). This might not work for your situation (almost all emails that go through our site are already HTML so its ok). We might also change this to be the same change the Shaun recommended and posted for the 5.5 release.
Note: We cannot support any code changes and do not support the DotNetNuke Framework directly, so please use this updated DLL at your own risk and make a full backup of your web site beforehand. The code changes were some minor tweaks to the Mail.vb file to avoid the IsHTML call. Also note if you add or update any forum threads on this issue that you have updated the DLL as you will be running on a modified version of 5.4.4 and not the actual release of DotNetNuke Corp.
You should already be running on 5.4.4 Community Edition BEFORE placing this file here. You can download the file by contacting us under www.datasprings.com, Contact Us. Currently the file will be avaliable for existing customers of our starting around the last week of August.
Thanks,
Chad
www.datasprings.com