diff --git a/README.md b/README.md index e21ea82..2d942b1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Denomailer - an SMTP client for Deno +# Denomailer - an SMTP client for Deno + [![deno module](https://shield.deno.dev/x/denomailer)](https://deno.land/x/denomailer) > This was forked from https://github.com/manyuanrong/deno-smtp but now is much diff --git a/client/basic/client.ts b/client/basic/client.ts index 03d6a24..51429e9 100644 --- a/client/basic/client.ts +++ b/client/basic/client.ts @@ -72,6 +72,7 @@ export class SMTPClient { async send(config: ResolvedSendConfig) { await this.#ready; + let dataMode = false; try { await this.#que.que(); @@ -117,6 +118,7 @@ export class SMTPClient { ); } + dataMode = true; await this.#connection.writeCmd("DATA"); this.#connection.assertCode( await this.#connection.readCmd(), @@ -318,9 +320,17 @@ export class SMTPClient { await this.#connection.readCmd(), CommandCode.OK, ); + dataMode = false; await this.#cleanup(); this.#que.next(); } catch (ex) { + if (dataMode) { + console.error("Error while in datamode - connection not revoverable"); + queueMicrotask(() => { + this.#connection.conn?.close(); + }); + throw ex; + } await this.#cleanup(); this.#que.next(); throw ex; diff --git a/client/basic/connection.ts b/client/basic/connection.ts index 467a509..45c4c82 100644 --- a/client/basic/connection.ts +++ b/client/basic/connection.ts @@ -77,8 +77,9 @@ export class SMTPConnection { } const nonNullResult: string[] = - (result.at(-1) === null ? result.slice(0, result.length - 1) : // deno-lint-ignore no-explicit-any - result) as any; + (result.at(-1) === null + ? result.slice(0, result.length - 1) // deno-lint-ignore no-explicit-any + : result) as any; if (nonNullResult.length === 0) return null;