EC-Nordbund / denomailer

A SMTP-Client implementation for deno (to send mails!)
https://deno.land/x/denomailer
MIT License
50 stars 16 forks source link

Corrupt message error when trying to connect with `STARTTLS` #21

Closed ghost closed 2 years ago

ghost commented 2 years ago

Describe the bug

Corrupt message error when trying to connect to https://ethereal.email on port 587 with STARTTLS.

error: Uncaught (in promise) InvalidData: received corrupt message
      const rr = await this.#rd.read(this.#buf.subarray(this.#w));
                 ^
    at async read (deno:ext/net/01_net.js:28:19)
    at async BufReader.#fill (https://deno.land/std@0.130.0/io/buffer.ts:323:18)
    at async BufReader.readSlice (https://deno.land/std@0.130.0/io/buffer.ts:609:9)
    at async BufReader.readLine (https://deno.land/std@0.130.0/io/buffer.ts:497:14)
    at async TextProtoReader.readLineSlice (https://deno.land/std@0.130.0/textproto/mod.ts:131:11)
    at async TextProtoReader.readLine (https://deno.land/std@0.130.0/textproto/mod.ts:33:15)
    at async SMTPConnection.readCmd (https://deno.land/x/denomailer@1.0.1/client/basic/connection.ts:76:19)
    at async SMTPClient.#prepareConnection (https://deno.land/x/denomailer@1.0.1/client/basic/client.ts:302:7)
    at async https://deno.land/x/denomailer@1.0.1/client/basic/client.ts:55:7

Code example

import { SMTPClient } from "https://deno.land/x/denomailer@1.0.1/mod.ts";

const auth = {
  username: /* redacted */,
  password:  /* redacted */,
};

export const email = new SMTPClient({
  connection: {
    hostname: "smtp.ethereal.email",
    port: 587,
    tls: true,
    auth,
  },
});

Logs

deno 1.21.1 (release, aarch64-apple-darwin)
v8 10.0.139.17
typescript 4.6.2
mathe42 commented 2 years ago

Don't set tls: true. As you want to use STARTTLS and not TLS.

STARTTLS = unencrypted connection that gets "upgraded" to a encrypted connection TLS = directly create an encrypted connection

Note that unless you set debug.allowUnsecure to true emails are only send when the connection is encrypted.

ghost commented 2 years ago

Thanks.

mathe42 commented 2 years ago

No problem!