nodemailer / smtp-server

Create custom SMTP servers on the fly
Other
846 stars 145 forks source link

TLS with Letsencrypt not working (NetworkTimeoutError) #198

Closed terion-name closed 9 months ago

terion-name commented 9 months ago

After enabling tls smtp connection can't establish (testing with thunderbird) — getting NetworkTimeoutError

Tried different configuration options, currently this:

const smtpConfig = {
        secure: !!sslDomain,
        name: sslDomain || 'localhost',
        tls: {
            rejectUnauthorized: false,
            servername: sslDomain || 'localhost'
        },
        debug: env.NODE_ENV === "development",
        authOptional: false,
        allowInsecureAuth: true,
        key: sslDomain ? fs.readFileSync(`${env.CERT_DIR}${sslDomain}/privkey.pem`, 'utf-8') : undefined,
        cert: sslDomain ? fs.readFileSync(`${env.CERT_DIR}${sslDomain}/cert.pem`, 'utf-8') : undefined,
        ca: sslDomain ? fs.readFileSync(`${env.CERT_DIR}${sslDomain}/fullchain.pem`, 'utf-8') : undefined,
        onAuth(auth, session, callback) {
            log('auth', session)
            callback()
        },
        onData,
        onConnect(session, callback) {
            log('Connected', session)
            callback()
        },
        onSecure(socket, session, callback) {
            log('Secure', session)
            callback()
        }
    }

Certs are from letsencrypt, the domain is public but pointing to 127.0.0.1 for testing

Even with rejectUnauthorized: false and allowInsecureAuth: true — no luck

Without ssl on 587 port everything is working fine

Several days of debug and nothing =(

andris9 commented 9 months ago

Make sure you have set the port and host correctly, and then use the openssl tool to test the connection

$ openssl s_client -crlf -servername example.com -connect 127.0.0.1:465

If the connection attempt does not show up in SMTP-Server's output log, you are connecting to somewhere else, but not against the SMTP-Server.

terion-name commented 9 months ago

Make sure you have set the port and host correctly, and then use the openssl tool to test the connection

$ openssl s_client -crlf -servername example.com -connect 127.0.0.1:465

If the connection attempt does not show up in SMTP-Server's output log, you are connecting to somewhere else, but not against the SMTP-Server.

openssl s_client -crlf -servername localhost.**** -connect 127.0.0.1:465
CONNECTED(00000003)
terion-name commented 9 months ago

everything set up correctly =(

Снимок экрана 2023-10-04 в 16 54 29
terion-name commented 9 months ago

@andris9 my mistake in issue description: not ConnectionRefusedError but NetworkTimeoutError, copied error code from old logs when was submitting

terion-name commented 9 months ago

@andris9 well, I've figured out. I've run it in Bun — and it doesn't work there =( With node it's ok..