notiz-dev / notiz

Frontend for notiz.dev. Built with Angular and Scully 👋
https://notiz.dev
67 stars 9 forks source link

Send Emails with NestJS #146

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

Send Emails with NestJS

Create Email Templates and send them with nodemailer from your Nest application

https://notiz.dev/blog/send-emails-with-nestjs

keithhuels commented 3 years ago

I am getting an exception : "Cannot destructure property 'templateName' of 'precompile(...)' as it is undefined. Any idea what to do? Only thing I've found on Google after hours of looking is to try and add "./" before the template name in mail.module.ts

tejo-ak commented 3 years ago

The same error: "Cannot destructure property 'templateName' of 'precompile(...)' as it is undefined So frustrating since the error message doesn't help

marcjulian commented 3 years ago

Do you have a repo to reproduce this error? Does this error occure in this example https://github.com/notiz-dev/nestjs-mailer for you as well?

marcjulian commented 3 years ago

I found this issue https://github.com/nest-modules/mailer/issues/570, are you using @nestjs-modules/mailer@1.6.0? Try out version 1.5.1 until the issue is fixed for the new version.

@keithhuels as you mentiond adding ./ before the template name is curretly the workaround for the 1.6.0 version https://github.com/nest-modules/mailer/issues/550#issuecomment-822249747

parideis commented 3 years ago

There is a comma "," missing in the compiler options. (In the article) Thanks for the article! :)

  "compilerOptions": {
    "assets": ["mail/templates/**/*"] // 👈 missing comma
    "watchAssets": true
  }
keithhuels commented 3 years ago

Yes, it works now that I put "./" in front of the specific template I am using in the mail service.

keithhuels commented 3 years ago

Another quick note, you have a "USER_FROM" in the .env file but it's not being used in the service. I believe it should be:

from: "No Reply" <${config.get('MAIL_FROM')}>,

marcjulian commented 3 years ago

Thanks @parideis and @keithhuels for spotting, I updated the article!

no-on3 commented 3 years ago

if you're using EJS, make sure you set the strict mode to false in the config, else you'll always get undefined variable in ejs template or use locals variable : <%= user %> becomes <%= locals.user %>

vprazuck commented 3 years ago

Try this in your mailservices.ts template: './templates/confirmation' Refer the location of the template you want to send.

justDare commented 3 years ago

First off, great tutorial! I followed it start to finish with no hiccups. Have you found a way to include template styling other than inlining them (partials, linking to static assets, etc.)?

Grimmig18 commented 3 years ago

Hi, first of, great job with the blog post, following the steps has been really easy and everything works as expected!

I do have one question though: Is there a way to separate out styling files (.css) or do I have to define styling in the handlebars files? I tried extracting the styling in a style.css file in the same directory as the handlebars file, but it seem like it isn't resolved properly. I have checked, that the .css file is also transported into the dist folder.

Anesca38 commented 3 years ago

Hi, thanks for that tutorial !

I'm having some trouble with the template part of things though.

first of template seems to not go where they would be supposed to in the dist folder. it comes out as :

Dist |-mail/templates |-src |-mail/mail.module.js

Wich is kinda strange, and not consistent with what you've got on the tutorial. Because of that i've got the "Cannot destructure property 'templateName' of 'precompile(...)' as it is undefined." error but adding the "./" to template doesn't change a thing.

I've tried tinkering around with no luck :/

ldulcic commented 3 years ago

I had a problem where templates where copied to dist folder instead of dist/src. I updated nest-cli.json to make it work:

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "assets": [{ "include": "mail/templates/**/*", "outDir": "dist/src" }],
    "watchAssets": true
  }
}

outDir tells compiler to copy templates to src folder, it works now.

Anesca38 commented 3 years ago

I had a problem where templates where copied to dist folder instead of dist/src. I updated nest-cli.json to make it work:

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "assets": [{ "include": "mail/templates/**/*", "outDir": "dist/src" }],
    "watchAssets": true
  }
}

outDir tells compiler to copy templates to src folder, it works now.

Thanks a lot !

sharon-asana commented 3 years ago

thanks for the amazing tutorial. when installing i get see 8 high severity vulnerabilities:

css-what  <5.0.1
Severity: high
Denial of Service - https://npmjs.com/advisories/1754
tk6ix9ine commented 3 years ago

Thanks for the article. As you suggested above, I had to add ./ to the template name. Outside of that everything worked perfect!

wsdydeni commented 3 years ago

How to build such a blog theme,thinks!