Nest js send email using handlebars with static image

1k views Asked by At

I am trying to send email that has to contain static image. The problem involves the way how to pass src for image. I mean for now I have to provide full path with origin like http://localhost:3000/logo.png and it works. But is this possible to provide only relative path for instance src=logo.png and it would work the same way?

Here is my hbs file:

<h2 class="header">Welcome {{ name }},</h2>
<p>Please the link click below to confirm your email address</p>
<p>
    <a href="{{ url }}">Confirm your email</a>
</p>

<p>If you did not request this email you can safely ignore it.</p>
<br>
<footer >
    <p>Best regards, <br><br> Bookify team</p>
    <div class="image-container">
        <img src="http://localhost:3000/logo.png" alt="Bookify logo">
    </div>
</footer>

main.ts:

app.useStaticAssets(join(__dirname, '..', 'public'));
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');`

app.module.ts:

ServeStaticModule.forRoot({
   rootPath: join(__dirname, '..', 'public'),
 }),

nest-cli.json:

"compilerOptions": {
    "assets": [
      {
        "include": "../views/**/*.hbs",
        "outDir": "dist/views"
      },
      {
        "include": "../public/**/*.{png, jpg}",
        "outDir": "dist/public"
      }
    ],
    "watchAssets": true
  }

Configuration for mailermodule:

export const mailerConfig: MailerAsyncOptions = {
  useFactory: () =>
    ({
      transport: {
        host: process.env.SMTP_HOST,
        port: process.env.SMTP_PORT,
        secure: false,
        auth: {
          user: process.env.SMTP_AUTH_USER,
          pass: process.env.SMTP_AUTH_PASSWORD,
        },
      },
      defaults: {
        from: process.env.WEBSITE_EMAIL,
      },
      template: {
        dir: join(__dirname, '../../views'),
        adapter: new HandlebarsAdapter(),
        options: {
          strict: true,
        },
      },
    } as MailerOptions),
};
0

There are 0 answers