Home > database >  Nodemailer with gmail get ETIMEDOUT error
Nodemailer with gmail get ETIMEDOUT error

Time:10-11

I just deploy my nodejs api on Scaleway and when I try to send a mail from it, i get the following error, while it works like a charm locally :

command: 'CONN'

code: 'ETIMEDOUT',

at processTimers (internal/timers.js:500:7) {

at listOnTimeout (internal/timers.js:557:17)

at Timeout.<anonymous> (/app/node_modules/nodemailer/lib/smtp-connection/index.js:229:22)

at SMTPConnection._onError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:760:20)

at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:774:19)

Error: Connection timeout

I'm using the following nodemailer transporter configuration :

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
    user: process.env.MAIL_ADRESS,
    pass: process.env.MAIL_PASSWORD
}
});

So I try to use the debug option from nodemailer transporter and I figure out that the resolved IP addresses are different.

Locally, the resolved IP address is the following :

 DEBUG [pfKLJKySPY] Resolved smtp.gmail.com as 142.251.5.108 [cache miss]

While in production, the resolved IP is the following :

DEBUG [vgPMKJtFZT] Resolved smtp.gmail.com as 74.125.140.108 [cache miss]

Also, I checked that the container my docker image is running on is not blocking port 456 used by SMTP and no firewall is enabled.

Do you have any idea ?

CodePudding user response:

I figured out that for the service to work in production, from my server, I had to configure the transport as follows:

const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false, 
requireTLS: true,
logger: true,
debug: true,
auth: {
    user: process.env.MAIL_ADRESS,
    pass: process.env.MAIL_PASSWORD
},

});

Now i'm able to send mail from gmail through nodemailer from my server !

The port has to be configured on 587 and requireTLS has to be true. Now, the resolved IP address is the following :

DEBUG [PHpdgG5NDWI] Resolved smtp.gmail.com as 66.102.1.109 [cache miss]

And with this address I have no more timeout errors !!!

  • Related