Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node-RED and nodemailer - Error: unable to verify the first certificate

I am trying to make something very basic work and it just isn't working for me. I have a simple Node-RED flow with an inject input node and an email output node:

inject to email nodes

The properties of the email node look like this:

email config window

The error says:

"7/28/2017, 11:43:28 AM node: [email protected] msg : error "Error: unable to verify the first certificate"

I am able to manually send unauthenticated email through this server via telnet. Even if I enter account creds it gives me the same "Error: unable to verify the first certificate".

Am I missing something simple?

like image 588
Eric Avatar asked Jul 28 '17 18:07

Eric


People also ask

How do I fix unable to verify the first certificate?

Try adding the appropriate root certificate globalAgent.options.ca = require('ssl-root-cas/latest'). create(); to your application. The SSL Root CAs npm package (as used here) is a very useful package regarding this problem.

How do I fix unable to verify the first certificate in node JS?

To fix 'Error: unable to verify the first certificate' in Node. js, we should set the appropriate root certificate. require('https'). globalAgent.options.ca = require('ssl-root-cas/latest').

What does Unable to verify the first certificate mean?

unable to verify the first certificate. The certificate chain is incomplete. It means that the webserver you are connecting to is misconfigured and did not include the intermediate certificate in the certificate chain it sent to you.

What is Node_extra_ca_certs?

NODE_EXTRA_CA_CERTS . process stores information about the node process running. env stores all the environment variables (that get populated by dotenv-webpack ).


2 Answers

I don't have enough reputation to write a comment, but i am adding this line for the previous reply, somebody might need it,

to bypass this error in Node.js program, type:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
like image 70
Tarık Seyceri Avatar answered Sep 26 '22 03:09

Tarık Seyceri


The problem is that the mail server you are connecting to is using SSL and the certificate it is supplying is not signed by one of the trusted CA's built into the Node.JS implementation you are using.

I'm guessing it's a self signed certificate.

The Error says that Node.JS can not verify the first certificate in the presented chain.

My best guess is that Nodemailer (which is used under the covers by the email node) is seeing the STARTTLS option listed when it sends the EHLO command as it starts the connection to the mail server and is trying to upgrade the connection to one that is secure.

While I really wouldn't normally recommend this, you can turn off Node.JS's cert checking by exporting the following environment variable before starting Node-RED:

NODE_TLS_REJECT_UNAUTHORIZED=0

This turns off ALL certificate checking, so you are open to man in the middle attacks for any TLS/SSL connection made from Node-RED.

The real solution here is to get a proper certificate for the mail server, maybe something from the letsencrypt project especially if this mail server is internet facing in any way.

like image 31
hardillb Avatar answered Sep 26 '22 03:09

hardillb