-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.6.0 Ignores my module config template.dir #550
Comments
Same issue here |
Same issue here, with ejsadapter too. |
Looking at lib/adapters/handlebars.adapter.ts I've figured it out: the mail template must start wit createMailerModuleOptions(): MailerOptions {
const options =
{
transport: {
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
secure: false, // TODO - Upgrade later with STARTTLS
ignoreTLS: true,
},
defaults: {
from: process.env.MAIL_FROM_ADDRESS,
},
template: {
dir: `${process.cwd()}/src/shared/provider/email/template/`,
adapter: new HandlebarsAdapter(),
options: {
strict: true,
},
},
};
return options;
}
public test(): void {
this
.mailerService
.sendMail({
to: 'me@myself.com',
subject: 'Testing Nest Mailermodule with template ✔',
template: `./index.hbs`,
context: {
code: 'cf1a3f828287',
username: 'john doe',
},
})
.then((success) => {
console.log(success)
})
.catch((err) => {
console.log(err)
});
}
} That's really obscure. The existence of a global template option made think that the email template option should be only |
That was it! Thanks a lot! |
That's a breaking change with v1.6.0
with version 1.6.0 it has to be changed to
as @lzkill mentioned already |
Yeah, this is not intuitive at all, and if you read the code it makes you think the template is in the same directory as the usage. |
for me trick with
worked for me |
My directory
The project needs to be packaged at the end, so package the template static file in the dist directory. Remember to add the configuration in the nest-cli.json {
"collection": "@nestjs/schematics",
"sourceRoot": "src",
// Add this configuration
"compilerOptions": {
"assets": ["templates/**/*"]
}
} this.mailerService.sendMail({
to: 'xxxxx@x.com',
from: 'yyyyy@yy.com',
subject: 'test',
// I wrote it like this before template: 'welcome.pug', but I failed
// Then I changed it to look like this
template: './welcome.pug'
})
.then((res) => { console.log(res) })
.catch((e) => { console.log(e) });
useFactory: () => ({
transport: 'smtps://xxx@xx.com:pass@smtp.xx.com',
defaults: {
from: '"nest-modules" <modules@nestjs.com>'
},
template: {
dir: path.join(__dirname, 'templates'),
adapter: new PugAdapter(),
options: {
strict: true
}
}
}) |
Config:
Service:
This worked with
1.5.1
but on upgrading to1.6.0
it stopped working. However, if I changed the template to,it works again.
The error thrown is:
The text was updated successfully, but these errors were encountered: