2

in my Drupal 8 installation I'm using mailsystem module in combination with swiftmailer module. Everything works fine so far, my swiftmailer twig template inside the templates folder of my custom theme is recognized and works as it should in general.

Problem:

When I want to embed a logo inside my template (as inline image), the image can't be loaded. It renders the template and shows a broken image placeholder. I used the code mentioned in readme.txt (see point 3.2.2) of swiftmailer module:

<img src="image:/themes/MYTHEME/logo.png">

Same error when I use

<img src="image:{{ base_url }}/themes/MYTHEME/logo.png">

Logo path is generally working, use the same for my theme in general.

The image is embedded also inside the email (using MailHog to check it):

Content-Type: image/png; name=logo.png

Content-Transfer-Encoding: base64

Content-ID: <f8a965e25fc041c5af9318b9d71cd3d1@mysite.site>

Content-Disposition: inline; filename=logo.png

.... image code following ....

How can I get my logo image inside my email correctly? Would like to avoid simply setting a linked image it to my webserver if possible,to minimize webserver traffic.

Thanks in advance :)

1

I was able to generate the base path for absolute links by using this twig filter in my template file:

{{ base_url ~ directory }}

There is more detail on the swiftmailer issue page here: https://www.drupal.org/project/swiftmailer/issues/2809359

1

The trailing slash was not added to the preprocess function so you need to do something like this:

<img src="{{ base_url ~ '/' ~ directory }}/img/mail-logo.png" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.