0

I am trying to send emails using Handlebars email templates. The problem is that I am not able to use static assets (css file, images...) in the HB code. I have figured out I can paste in CSS to the HB file, using <style> tag, but I can not do this with images.

File structure (inside src folder):

File structure (inside src folder)

HTML tag which trying to access an image:

<a href=''>
   <img src='./img/cocacola.jpg' width='802' height='250' />
</a>

Settings in main.ts:

//Template settings
app.useStaticAssets(join(__dirname, '..', 'src', 'templates'))
app.setBaseViewsDir(join(__dirname, '..', 'src', 'templates'))
app.setViewEngine('hbs')

In the end the email is successfully sent, but the images are missing.

gomark
  • 35
  • 6
  • I think you image `src` would need to be an absolute URI as the email client does not know to what URI this `src` is relative. See: https://stackoverflow.com/q/2005079/3397771 – 76484 Oct 13 '21 at 12:56

0 Answers0