nest-modules / mailer

📨 A mailer module for Nest framework (node.js)
https://nest-modules.github.io/mailer/
MIT License
846 stars 177 forks source link

Got an error when try to send email without use of any template engine #16

Closed bzsozsy closed 5 years ago

bzsozsy commented 5 years ago

Tried to send email just without any template engine like in your example:

this.mailerProvider.sendMail({
  to: 'test@nestjs.com', // sender address
  from: 'noreply@nestjs.com', // list of receivers
  subject: 'Testing Nest MailerModule ✔', // Subject line
  text: 'welcome', // plaintext body
  html: '<b>welcome</b>' // HTML body content
})

I got the following: UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined.

The error came from this function(mailer.provider.ts:63):

private getTemplatePath(templateDir: string, templateName?: string, extension?: string) {
    return path.join(process.cwd(), templateDir || './public/templates', templateName) + extension;
  }

There is no default value for the templateName variable and in this case the path got undefined argument, which caused the above error. I was set a dummy empty template file path to sendMail's argument and it's solved the issue, but in this case I must have to put a file path and create an empty file.

pawpartyka commented 5 years ago

@bzsozsy check if the error still occurs with the new 1.0.3 release

Avejack commented 5 years ago

Sadly I get this same error. I am using version 1.1.3.

Avejack commented 5 years ago

I have noticed that it works fine if I provide the text and the html property. Is that by design? Shouldn't it be like: Is template given, use template. If not check if html is given and use html. If not check if text is given and use text. If text also isn't given throw an error. Am i missing something? Thanks!

some-git-user commented 3 years ago

Had the same issue today. Thanks @Avejack "provide the text and the html property" fixed this behaviour. @bzsozsy @partykos Why is this issue closed?

miadabdi commented 7 months ago

With version 1.10.3 I still get the same error, If html property is passed no error is thrown, but if I want to only work with text propery, I get the error. I can work with text property if I don't use template engines as well, but that is not convinent.