Error Sending Email: Length cannot be less than zero

Platform version in cloud

So I've run into a problem sending an email that I haven't seen before and all related threads don't seem to have an answer for it either.

I have an email that is used in numerous different scenarios that basically wraps third-party provided HTML templates with some introduction text and then sends the email to users.

So far it has worked for several different HTML templates without issue, but with one template I'm now getting the below error:

Length cannot be less than zero.

Parameter name: length

   at System.String.Substring(Int32 startIndex, Int32 length)

  at OutSystems.HubEdition.RuntimePlatform.Email.EmailProcessor.#9Hb(String inputHtml, String startReExpr, String endReExpr, #fIb if, Boolean preserveContents)

at OutSystems.HubEdition.RuntimePlatform.Email.EmailProcessor.#8Hb(String inputHtml, String startReExpr, String endReExpr, Boolean preserveContents)

at OutSystems.HubEdition.RuntimePlatform.Email.EmailProcessor.#5Hb(String emailBody)

at OutSystems.HubEdition.RuntimePlatform.Email.EmailProcessor.CreateEmail(String bodyUrl, String emailSubject, String emailBody, String from, String to, String cc, String bcc, Int32 activityId, Int32 tenantId, Int32 eSpaceId, String emailDefSSKey, Boolean storeContent, List`1 headers, List`1 attachments, String realHostname)

at ssOutputService.Flows.FlowEmailFlow.ScrneVoucherEmail.Render(HtmlTextWriter writer)

Unfortunately I can't share the template that is causing the problem but is there anything I should be looking for within the HTML that could cause this error to be thrown by the EmailProcessor? I have tried removing parts of the template to see if that makes a difference but no joy yet.

Or are there some limits to email content that I'm not aware of?



HI Douglas,

By looking at the error it seems like the length property of may be list or anything else you are using in your template is null or a negative value.

Could you check your logic and see where are you using this ?




Hi Pramod,

Thanks for the reply. I should have explained myself better.

The email template doesn't change between uses. The only thing that changes is an un-escaped expression containing HTML from a 3rd-party.

For some reason, for this particular HTML the EmailProcessor throws that error. There are no lists or anything else that I'm passing into the email template that can be null or negative.

But not to worry. Through a trial and error process I've now found the solution.

The 3rd-party HTML contained a section like:

<!--[if !mso]-->
<td>Blah blah blah</td>

When I removed this the email sent successfully.

Can anyone explain why the email processor didn't like this?