mailjet / mailjet-apiv3-nodejs

[API v3] Official Mailjet API v3 NodeJS wrapper
https://dev.mailjet.com
MIT License
236 stars 69 forks source link

Mailjet not send the template language part in the message #243

Closed sayinmehmet47 closed 1 year ago

sayinmehmet47 commented 1 year ago

I am using mailjet to send notification to user if they upload a file. So I created a template like that

enter image description here enter image description here

But when i got the message it only send the title and first description part, it does not send the template language part. enter image description here

I dont know if I send the request wrongly. That is how I implemented the request

 async sendNotificationMail() {
    try {
      await this.mailClient.sendMail({
        to: 'mehmet.sayin@steiner.ch',
        template: '4714581',
        AdvanceErrorHandling: true,
        variables: {
          userName: 'Mehmet',
          projectName: 'Test Project',
          senderName: 'Mehmet',
          senderEmail: 'sayinmehmet47@gmail.ch',
        },
      });
    } catch (error) {
      this.logger.error(error);
    }
  }

am I need to activate sth to show also template language part? I also tried it with TemplateLanguage: true, but does not show that part.

ai-wintermute commented 1 year ago

Hi @sayinmehmet47 it should be a 'Mj-TemplateLanguage': true property not a TemplateLanguage. Here's a detailed documentation on that, please take a look.

sayinmehmet47 commented 1 year ago

@ai-wintermute thanks for your answer.I dont know if is is the case. I also defined it in the header and tried the Mj-TemplateLanguage=true. but did not worked for me. HERE how is I defined it

  async sendMail(mailDto: MailDto) {
    const sendMailOptions: ISendMailOptions = {
      to: mailDto.to,
      from: mailDto.from ?? this.defaultMailFrom,
      text: mailDto.text,
      subject: mailDto.subject,
      html: mailDto.html,
      headers: {
        'X-MJ-TemplateID': mailDto.template || '',
        'X-Mj-TemplateLanguage': '1',
        'X-MJ-Vars': JSON.stringify(mailDto.variables || {}),
        'X-MJ-TemplateErrorReporting': '1',
      },
    };

    this.logger.debug('sendMail', JSON.stringify(sendMailOptions));
    try {
      await this.mailerService.sendMail(sendMailOptions);
    } catch (error) {
      this.logger.error('Sending Mail failed', error);
    }
  }