mailjet / mailjet-apiv3-nodejs

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

Hostname/IP does not match certificate's altnames: Host: api.mailjet.com. is not in the cert's altnames #219

Closed linaia closed 1 year ago

linaia commented 2 years ago

Hi,

When I want to send a mail with the API, like this :

mailjet = require('node-mailjet').apiConnect(my_public_key, my_private_key);
mailjet.post('send', { version: 'v3.1' }).request(
        {
          Messages: [
            {
              From: {
                Email: "xxxxx@xxx.com",
                Name: 'Terdici'
              },

              To: {
                Email: "test@mail.com",
                Name: "test"
              },
              Subject: "subject",
              HTMLPart: "texte html",
              TextPart: "send mail"
            }
          ]
        }
  );

I've got this error :

Hostname/IP does not match certificate's altnames: Host: api.mailjet.com. is not in the cert's altnames: DNS:collectes.terdici-agri.fr, DNS:www.collectes.terdici-agri.fr

My Mailjet config is : terdici_domaine terdici_spf_dkim

Did I forget in the dns config ?

linaia commented 2 years ago

After some tests with a script, the message can be send on the host server with a simple code :

const mailjet = require ('node-mailjet').apiConnect(xxx, yyyy);
const request = mailjet.post("send", {'version': 'v3.1'}).request({}) 
request.then((result) => {
    console.log(result.body)
  }).catch((err) => {
    console.log(err)
  })

But not inside a docker (nodejs 16 image) running on the same server, full error message :

Error: Unsuccessful: Error Code: "ERR_TLS_CERT_ALTNAME_INVALID" Message: "Hostname/IP does not match certificate's altnames: Host: [api.mailjet.com](http://api.mailjet.com/). is not in the cert's altnames: DNS:[collectes.terdici-agri.fr](http://collectes.terdici-agri.fr/), DNS:[www.collectes.terdici-agri.fr](http://www.collectes.terdici-agri.fr/)"
    at e.<anonymous> (/app/terdici-collecte/terdici-collecte-api/mailjet/node_modules/node-mailjet/mailjet.node.js:2:37945)
    at /app/terdici-collecte/terdici-collecte-api/mailjet/node_modules/node-mailjet/mailjet.node.js:2:33876
    at Object.throw (/app/terdici-collecte/terdici-collecte-api/mailjet/node_modules/node-mailjet/mailjet.node.js:2:33981)
    at r (/app/terdici-collecte/terdici-collecte-api/mailjet/node_modules/node-mailjet/mailjet.node.js:2:32746)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_TLS_CERT_ALTNAME_INVALID',
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [Function (anonymous)],
    transformRequest: [ [Function (anonymous)] ],
    transformResponse: [Function: transformResponse],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function] },
    validateStatus: [Function: validateStatus],
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'User-Agent': 'mailjet-api-v3-nodejs/5.1.1',
      'Content-Length': 385
    },
    url: 'https://api.mailjet.com/v3.1/send',
    params: {},
    data: `{"Messages":[{"From":{"Email":"[xxxx@terdici-agri.fr](mailto:xxx@terdici-agri.fr)","Name":"Jules"},"To":[{"Email":"[xxxx](mailto:xxxxx)","Name":"Laurent"}],"Subject":"Greetings from Mailjet.","TextPart":"My first Mailjet email","HTMLPart":"<h3>Dear passenger 1, welcome to <a href='https://www.mailjet.com/'>Mailjet</a>!</h3><br />May the delivery force be with you!","CustomID":"AppGettingStartedTest"}]}`,
    method: 'post',
    responseType: 'json',
    auth: {
      username: 'xxxx',
      password: 'yyyy'
    }
  },
  response: null,
  statusCode: null,
  statusText: null,
  originalMessage: "Hostname/IP does not match certificate's altnames: Host: [api.mailjet.com](http://api.mailjet.com/). is not in the cert's altnames: DNS:[collectes.terdici-agri.fr](http://collectes.terdici-agri.fr/), DNS:[www.collectes.terdici-agri.fr](http://www.collectes.terdici-agri.fr/)"
}
linaia commented 2 years ago

The error is thrown by axios request (https://github.com/mailjet/mailjet-apiv3-nodejs/blob/master/lib/request/index.ts: 324)

linaia commented 2 years ago

I see that it is a change since 4.0.1 : Replace superagent http client with axios

@scroll17 Denys would you please have a look ? Any idea what is wrong ?

linaia commented 2 years ago

We've tested nodemailer with SMTP from the docker and it works fine, so you the issue is from this library.

const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
  host: "in-v3.mailjet.com",
  port: 587,
  auth: {
    user: 'apikey',
    pass: 'secret'
  }
});
let result = transporter.sendMail({
        from: "no-reply@ourdomain.fr",
        to: "anybody@loveis.all",
        subject: "test sending",
        text: "OK",
      }).then((result) => {
    console.log(result)
  }).catch((err) => {
    console.log(err)
  })
ai-wintermute commented 1 year ago

Hi @linaia did you try using the Support center? It seems to be a configuration error not the library one.

ai-wintermute commented 1 year ago

I'm closing this issue as it's not related to the library.