[SOLVED] Email templating with Fluid support?

Is there an example for emails where I can see how to create email templates in Neos, while making use of Fluid, view helpers etc ?

I am using sendTemplateEmail from Sandstorm.TemplateMailer EmailService class and the output in my log is weirdly messed up.

For example this markup:

    <td class="one-column">
         <table width="100%">

Transforms to this in my logged email:

          <td class=3D"one-column">
                    <table width=3D"1=

And inline syntax like {f:uri.resource(package: 'Vendor.Site', path: 'Images/email-header.jpg')} doesn’t parse.

I have no idea what should and what should not work in this case, thanks in advance !

I just created a simple template case to test.


    'An arbitrary email title',

Template file:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">

Logged email after execution:

<!DOCTYPE html>
<html lang=3D"en">
<meta http-equiv=3D"Content=
-Type" content=3D"text/html; charset=3Dutf-8">
<meta charset=3D"UTF-8">=


What is going on ? What is this weird 3D “prefix” before the equal character and the = \r at random points in my logged file ?

Woah, this looks like a charset issue to me… Did you store the template files as UTF-8?

It seems more like the correct way, how SwiftMailer treats long lines (IIRC 76 chars is the maximum) before it breaks into a new line, when delivering. But how does it look in your email reader?

Encoding is UTF-8 yeah, plus I only made use of basic ASCII characters in that template.

The line breaks are not a problem, but what about the equal sign (=) after a forced line-break and the 3D prefix before all equal signs in the original template ?

I don’t have a mail reader, I’m currently testing locally, meaning I’m logging the emails in sent-mail

      type: Neos\SwiftMailer\Transport\MboxTransport
        mboxPathAndFilename: '%FLOW_PATH_DATA%/Persistent/sent-mail'

Maybe have a look at Mailhog (https://github.com/mailhog/MailHog) - it’ll emulate a real inbox for you, so you can see what the rendered result looks like.

But the generated HTML is obviously invalid. I don’t need to test the looks of the email (yet), I first need to get it working properly.

Did you try var_dump-ing the $htmlBody here: https://github.com/sandstorm/TemplateMailer/blob/master/Classes/Domain/Service/EmailService.php#L93 to check if the weird stuff might be caused by Mbox writing the file to disk?

Hmmm, according to this source it seems that this is some kind of featured e-mail encoding. I guess I’ll need a client after all …

As noted in the above source, an online tool to decode quoted-printable format is: https://www.motobit.com/util/quoted-printable-decoder.asp
Alternatively, if I understand it correctly, setting a request header Content-Transfer-Encoding: quoted-printable will render the encoded HTML properly. Haven’t tested this.

Learned something new today.

Cheers, thanks for the tips everyone !

Alright, the encoding part mystery is solved, but I still have this bug with inline viewhelpers in my email layout.

I have an image loaded in fluid as below:

<img src="{f:uri.resource(package: 'Vendor.YouSite', path: 'Images/email-header.jpg')}" width="600" alt="" />

And the resulting rendered HTML is:

<img src=3D"%7Bf:uri.resource(package:%20'Ve=
ndor.YouSite',%20path:%20'Images/email-header.jpg')%7D" width=3D"600" alt=
=3D"" style=3D"border: 0; max-width: 600px; width: 100%; height: auto;">

Meaning the inline f:uri view helper is not parsed.

However, if I use the tag syntax the view helper is executed properly:

<img src="<f:uri.resource path='Images/email-header.jpg' package='Vendor.YouSite' />" width="600" alt="" />

Is this a bug or am I missing something ?

Hmm, that seems weird. Does a simple variable output, e.g. {foo}, work?

Yes, namespace definitions and variables work normally

Are you 100% sure that there is no syntax error in your inline VH call? Maybe a non-printable character or something? This could lead to Fluid not parsing the inline VH.

Well, you can never be 100% sure, but I did my double-checks and triple-checks. The project and path are correct, but still the view helper is only parsed when in tag format.

I copy-pasted my code here directly, only renamed the package name.

I have no explanation for this currently - I don’t really do anything special in that package at all. Maybe I can get around to checking this myself today, as I’m working on something related.

Cool thanks. So, did you manage to reproduce this ?

I tried this exact same thing (even copied your code) and it works perfectly fine in my setup - MailHog displays the image, so the VH gets parsed. Did you try with an email client like Mailhog in the meantime?

That’s weird. Thanks a lot for the test, looks like I’m doing something wrong. No, I didn’t try mailhog yet, because I manage to convert the quoted-printable HTML to common HTML.

I’ll try again and update soon, cheers !

Nope, tested again on my remote server with actual email configuration and the image is opted out with the syntax <img src="{f:uri.resource(path: 'Images/email-header.jpg', package='Vendor.Site')}" width="600" alt="" />

I would be surprised if an actual email service worked, because that would mean that the logging mode is not trustworthy for testing.

I wonder if it’s a problem that I load the image on Layout level instead of the template. Anyway, I don’t know what else to test, I’ll just use the tag syntax and update if I discover anything later.

Thanks a lot for your help !


this syntax is wrong:

It should be:

f:uri.resource(path: 'Images/email-header.jpg', package:'Vendor.Site')}

All the best,