Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve CERT_UNTRUSTED error in nodemailer

I am trying to send an email with nodemailer. I already managed to send it from another host but now I want to send emails from another address. These are the versions of nodemailer I am using (from my package.json):

"nodemailer": "1.3.4",
"nodemailer-smtp-transport": "1.0.2",

This is the information I have about my webmail:

RoundCube Mail Client Configuration

I set up nodemailer like this:

    var transport = nodemailer.createTransport(smtpTransport({
        host: 'securemail.linevast.de',
        port: 465,
        secure: true,
        auth: {
            user: '[email protected]', // this is my login name
            pass: 'mypassword'
        },
        maxConnections: 5,
        maxMessages: 10
    }));

And when I try to send an email I get the following error message.

[Error: certificate not trusted] code: 'CERT_UNTRUSTED'

The website is verified by GeoTrust Inc so I believe it is quite trustworthy. Is there a way to make nodemailer trust the certificate or force it to send the email even though it does not trust it?

Thank you for your help!

like image 295
arne.z Avatar asked Jun 08 '15 22:06

arne.z


People also ask

How do I debug Nodemailer?

Debugging options in Nodemailer It is simple with Nodemailer: set both debug and logger to true and you will be able to see all the data which is passed to the server as an output in the console. This way, you will be able to analyze the email sending process and quickly fix errors, if there are any.

What is TLS in Nodemailer?

tls – defines additional node. js TLSSocket options to be passed to the socket constructor, eg. {rejectUnauthorized: true}. tls.servername - is optional hostname for TLS validation if host was set to an IP address.

Can we use Nodemailer in production?

Nodemailer - Works locally but not on production.


1 Answers

Yes, you can tell nodemailer to not check the certificate trust.

This is the option:

tls: {rejectUnauthorized: false}

use it on the initial transport object:

var transporter = nodemailer.createTransport(smtpTransport('SMTP',{
        host: 'mail.mailserver.com',
        port: 587,
        auth: {
            user: '[email protected]',
            pass: 'passwd'
        },            
        authMethod:'NTLM',
        secure:false,
        // here it goes
        tls: {rejectUnauthorized: false},
        debug:true
    })
);
like image 123
jmingov Avatar answered Oct 10 '22 16:10

jmingov