Ektron Forms - Generate Plaintext Email

202 views Asked by At

In Ektron I have a form that generates an HTML email on submission and sends it to a mailbox ([email protected]). An application (MailReader) checks that mailbox, reads the messages, strips all markup, and saves the resulting messages for later use. This is a problem because all the text from the HTML email end up getting mashed together and are completely unreadable by someone using the MailReader app.

For example, this HTML:

<h1>Header1</h1>
<div>
   <h2>Header2</h2>
   <p>Some text in a paragraph.</p>
</div>

Becomes:

Header1Header2Some text in a paragraph.

I cannot change MailReader in any way, it will always strip any markup so my solution is to have Ektron generate an email that contains no HTML for just this form. I know the email is generated using XSLT transformations with the file /Workarea/controls/forms/DefaultFormEmailBody.xslt.

My attempt at my solution involved adding a hidden input to the form with name "__nohtml". Then the XSLT will do the following:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:choose>
        <xsl:when test="/field[starts-with(@name, '__nohtml')]">
            <xsl:output method="text" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:output method="html" />
        </xsl:otherwise>
    </xsl:choose>
    <xsl:template match="/">
        <xsl:choose>
            <xsl:when test="/field[starts-with(@name, '__nohtml')]">

                text output

            </xsl:when>
            <xsl:otherwise>

                html output

            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

But it never sends the email when I use this. I tried just rendering with this template on my own machine and I get errors. And I've also noticed that w3 documentation says the The xsl:output element is only allowed as a top-level element. That probably explains why I can't put it in the element.

I've also tried just completely omitting the element and it seems to default to HTML no matter what.

I've tried searching our local Ektron code for the point where the transformation occurs so I can tell Ektron to use the default XSLT in standard cases or use a different XSLT if __nohtml exists, but I don't know if that code is even accessible.

I would greatly appreciate it if someone can help me find a template that would allow either HTML or plaintext based on whether a field exists. If not then it would be equally awesome if someone could point me to the point of XSLT transformation in Ektron's code (if it's even accessible).

1

There are 1 answers

2
Andrew S On BEST ANSWER

I would recommend a form strategy to generate a version of an email that you build out. There should be a public override void OnAfterSubmit(FormData formData, FormSubmittedData submittedFormData, string formXml, CmsEventArgs eventArgs) that would allow you to create pull out the submitted form data (either in the raw object or I believe it returns the xml as well. From there you could just parse it and save your html file.