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

TLS connection throwing 'Bad resource ID' #56

Closed joshcancode closed 1 year ago

joshcancode commented 1 year ago

Describe the bug

TLS connections seem to work in deno-smtp, however trying to connect via TLS in denomailer is throwing a Bad resource ID error. I've removed the auth fields from the logs.

EDIT: Connections seem to work, the Bad resource ID error is coming from a catch statement in the "send" function. The connection itself seems to be okay.

To Reproduce

I have only tried this with domain.com SMTP connections, I'm unsure if the same happens with other domains.

The non-working denomailer code:

const client = new SMTPClient({
    connection: {
        hostname: "smtp.domain.com",
        port: 465,
        tls: true
    }
});

The working deno-smtp code:

await client.connectTLS({
  hostname: "smtp.domain.com",
  port: 465
})

Logs

deno 1.28.2 (release, x86_64-pc-windows-msvc)
v8 10.9.194.1
typescript 4.8.3
used resolved config
.debug
┌───────────────┬────────┐
│ (idx)         │ Values │
├───────────────┼────────┤
│ log           │ true   │
│ allowUnsecure │ false  │
│ encodeLB      │ false  │
│ noStartTLS    │ false  │
└───────────────┴────────┘
.connection
┌──────────┬───────────────────────────────────────────────────────────────────────┐
│ (idx)    │ Values                                                                │
├──────────┼───────────────────────────────────────────────────────────────────────┤
│ hostname │ "smtp.domain.com"                                                     │
│ port     │ 465                                                                   │
│ tls      │ true                                                                  │
└──────────┴───────────────────────────────────────────────────────────────────────┘
.pool
undefined
220 ESMTP Tue, 29 Nov 2022 10:03:38 -0500: UCE strictly prohibited
┌───────┬───────────────────┐
│ (idx) │ Values            │
├───────┼───────────────────┤
│     0 │ "EHLO"            │
│     1 │ "smtp.domain.com" │
└───────┴───────────────────┘
250-bosauthsmtp07.yourhostingaccount.com Hello smtp.domain.com [ *removed* ]
250-SIZE 34603008
250-8BITMIME
250-PIPELINING
250-PIPE_CONNECT
250-AUTH PLAIN LOGIN
250-CHUNKING
250-STARTTLS
250 HELP
┌───────┬────────────┐
│ (idx) │ Values     │
├───────┼────────────┤
│     0 │ "STARTTLS" │
└───────┴────────────┘
An error occured while sending an email: BadResource: Bad resource ID
error: Uncaught (in promise) Interrupted: operation canceled
    at async Object.pull (deno:ext/web/06_streams.js:689:29)
mathe42 commented 1 year ago

I think I fixed it. Could you try it by importing denomailer from https://raw.githubusercontent.com/EC-Nordbund/denomailer/fix/starttls_on_secure_connection/mod.ts ?

joshcancode commented 1 year ago

I think I fixed it. Could you try it by importing denomailer from https://raw.githubusercontent.com/EC-Nordbund/denomailer/fix/starttls_on_secure_connection/mod.ts ?

Yes, this works! Thank you very much.

mathe42 commented 1 year ago

Than I will merge that to main and make a release (should take about 5min)