Closed RRGT19 closed 10 months ago
Got it working by setting the correct dir
in template options.
To copy the email-templates to dist: Search in your project config for the assets
folder. This will be copied to dist. Add to the config also the your email-template folder.
Seeing code from https://github.com/nest-modules/mailer/blob/1df331559aced871d18354d7ad6f976ee6aa6496/lib/adapters/handlebars.adapter.ts#L38-L41, templates inside the directory pointed by the template.dir
options are expected to be prefixed with ./
.
This is actually a bug with fix pending in 9bee48b0e630c71c3702b83747dc41152670947e, that will be shipped in version >=1.6.1
any idea when we could have a release to get the fix? Thanks for your help!
I got it to work by stating the full path to template mailService like this
this.mailerService.sendMail({
to: to,
from: 'bla@gmail.com,
subject: subject,
template: path.join(process.cwd(), 'dist', 'mail', 'templates', `${template}.ejs`),
context: {
otp: generatedOTP,
},
});
But I'm still looking for a way to make it work using the dir
option in module.
I got it to work by stating the full path to template mailService like this
this.mailerService.sendMail({ to: to, from: 'bla@gmail.com, subject: subject, template: path.join(process.cwd(), 'dist', 'mail', 'templates', `${template}.ejs`), context: { otp: generatedOTP, }, });
But I'm still looking for a way to make it work using the
dir
option in module.
This Works with me
Is any one still having this issue, I resolved it by adding "$schema": "https://json.schemastore.org/nest-cli",
non of the other solutions worked until I added this tag.
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [{ "include": "config/mail/templates/**/*", "outDir": "dist" }],
"watchAssets": true
}
}
Can confirm that using the full path works, however would like to see a real fix for this
I managed to solve it setting the outDir
to dist/src
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [{ "include": "config/mail/templates/**/*", "outDir": "dist/src" }],
"watchAssets": true
}
}
I managed to solve it setting the
outDir
todist/src
{ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "assets": [{ "include": "config/mail/templates/**/*", "outDir": "dist/src" }], "watchAssets": true } }
This worked for me! thx :D
process.cwd(),
This worked for me
I managed to solve it setting the
outDir
todist/src
{ "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "assets": [{ "include": "config/mail/templates/**/*", "outDir": "dist/src" }], "watchAssets": true } }
Worked perfectly fine 💯
The same issue as this one, this issue is closed so, I'm creating a new one.
Error:
UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/my-awesome-project/dist/assets/templates/welcome.hbs'
package.json
nest-cli.json
application structure
MailerOptions
Send email method:
My issues:
.hbs
files are not copied to thedist
folder.Any help would be appreciated.