2

Am sending an email via adonis mailer and i would like to get the domain name to include in the images on the edge files but am stuck on how to add the domain name as emails sent dont display the images

So in my email edge file i have

<html>
       .....other stuff

   <img 
      src="{{ assetsUrl('images/logo.png') }}"
    />
 </html>

This doenst display the logo.

A quick check on the output of

{{assetsUrl('images/logo.png')}}

it displays

/images/logo.png

This shows that the domain name is not included i n the assetUrl helper. How can i get the domain name in the edge file, so that the src propery is complete to display the image

Geoff
  • 6,277
  • 23
  • 87
  • 197

2 Answers2

1

I have a solution but it's not perfect :

You can use .env variables (example: APP_URL, or custom)

Edge:

<img src="{{ APP_URL() }}{{ assetsUrl('images/logo.png') }}"/>

You need to create start/hooks.js :

const { hooks } = use('@adonisjs/ignitor')

hooks.after.providersBooted(() => {
    const Env = use('Env')
    const View = use('View')

    View.global('APP_URL', function () {
        return Env.get('APP_URL')
    })
})

Same issue : forum.adonisjs.com/t/grab-full-page-url/1998

crbast
  • 2,192
  • 1
  • 11
  • 21
0

For sending images in email, Adonis has functions for that.

const Helpers = use ('Helpers')

embed (filePath, cid, [options]) Embed an image into the HTML body using a content id:

message.embed (Helpers.publicPath ('logo.png'),

https://adonisjs.com/docs/4.1/mail

Jeziel
  • 1