Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidContentType when trying to write to connection over connectTls on port 587 #20951

Open
Unkn0wn0x opened this issue Oct 21, 2023 · 1 comment

Comments

@Unkn0wn0x
Copy link

Unkn0wn0x commented Oct 21, 2023

If I try to write into a open connection on port 587 via connectTls, I'm getting the error:

InvalidData: received corrupt message of type InvalidContentType
    at async write (ext:deno_net/01_net.js:32:10)
    at async sendEmail (<anonymous>:11:5)
    at async <anonymous>:17:1 {
  name: "InvalidData"
}

This is the code example I used / how the issue can be reproduced:

async function sendEmail() {

    const encoder = new TextEncoder();

    try {

        const conn = await Deno.connectTls({
            hostname: "smtp.mydomain.com",
            port: 587
        });

        await conn.write(encoder.encode("EHLO mydomain.com\r\n"));
        conn.close();

    } catch (error) {
        console.error(error);
    }
}

await sendEmail();

If I try to start the connection via connect and then switch the connection over with startTls, I'm getting the same error:

InvalidData: received corrupt message of type InvalidContentType
    at async write (ext:deno_net/01_net.js:32:10)
    at async sendEmail (<anonymous>:13:5)
    at async <anonymous>:19:1 {
  name: "InvalidData"
}

Code example:

async function sendEmail() {

    const encoder = new TextEncoder();

    let conn;
    try {

        conn = await Deno.connect({
            hostname: "smtp.mydomain.com",
            port: 587
        });
        const tlsConn = await Deno.startTls(conn, { hostname: "smtp.mydomain.com" });

        await tlsConn.write(encoder.encode("EHLO mydomain.com\r\n"));

        tlsConn.close();

    } catch (error) {
        console.error(error);
    }
}

await sendEmail();

This affects sending emails over a secure connection via Deno. On the other hand, when port 465 on the SMTP server is available, it works without any problems.

If I run openssl s_client -debug -starttls smtp -crlf smtp.mydomain.com:587 everything seems to work fine.

Any ideas how to fix this bug? It affects the Deno mailing packages like:

Could also be related to:

Especially:

Thanks in advance.

@hongkongkiwi
Copy link

Just hit this, port 587 on nodemailer using deno fails, but port 465 works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants