aboutsummaryrefslogtreecommitdiff
path: root/deno/mail-relay/dumb-smtp-server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'deno/mail-relay/dumb-smtp-server.ts')
-rw-r--r--deno/mail-relay/dumb-smtp-server.ts18
1 files changed, 9 insertions, 9 deletions
diff --git a/deno/mail-relay/dumb-smtp-server.ts b/deno/mail-relay/dumb-smtp-server.ts
index ac7069c..818cc88 100644
--- a/deno/mail-relay/dumb-smtp-server.ts
+++ b/deno/mail-relay/dumb-smtp-server.ts
@@ -12,6 +12,7 @@ function createResponses(host: string, port: number | string) {
RCPT: "250 2.1.5 Recipient OK",
DATA: "354 Start mail input; end with <CRLF>.<CRLF>",
QUIT: `211 2.0.0 ${serverName} closing connection`,
+ ACTIVE_CLOSE: "421 4.7.0 Please open a new connection to send more emails",
INVALID: "500 5.5.1 Error: command not recognized",
} as const;
}
@@ -46,7 +47,7 @@ export class DumbSmtpServer {
const [decoder, encoder] = [new TextDecoder(), new TextEncoder()];
const decode = (data: Uint8Array) => decoder.decode(data);
const send = async (s: string) => {
- console.info(LOG_TAG, "Send line: " + s);
+ console.info(LOG_TAG, "Send line:" + s);
await writer.write(encoder.encode(s + CRLF));
};
@@ -69,7 +70,7 @@ export class DumbSmtpServer {
buffer = buffer.slice(eolPos + CRLF.length);
if (rawMail == null) {
- console.info(LOG_TAG, "Received line: " + line);
+ console.info(LOG_TAG, "Received line:" + line);
const upperLine = line.toUpperCase();
if (upperLine.startsWith("EHLO") || upperLine.startsWith("HELO")) {
await send(this.#responses["EHLO"]);
@@ -85,23 +86,22 @@ export class DumbSmtpServer {
await send(this.#responses["QUIT"]);
return;
} else {
- console.warn(LOG_TAG, "Unrecognized command from client: " + line);
+ console.warn(LOG_TAG, "Unrecognized command from client:" + line);
await send(this.#responses["INVALID"]);
return;
}
} else {
if (line === ".") {
try {
- console.info(LOG_TAG, "Mail data Received, begin to relay...");
- const { message } = await this.#deliverer.deliverRaw(rawMail);
- await send(`250 2.6.0 ${message}`);
+ console.info(LOG_TAG, "Mail data received, begin to relay...");
+ const { smtpMessage } = await this.#deliverer.deliverRaw(rawMail);
+ await send(`250 2.6.0 ${smtpMessage}`);
rawMail = null;
- console.info(LOG_TAG, "Relay succeeded.");
} catch (err) {
console.error(LOG_TAG, "Relay failed.", err);
await send("554 5.3.0 Error: check server log");
- return;
}
+ await send(this.#responses["ACTIVE_CLOSE"]);
} else {
const dataLine = line.startsWith("..") ? line.slice(1) : line;
rawMail += dataLine + CRLF;
@@ -123,7 +123,7 @@ export class DumbSmtpServer {
try {
await this.#handleConnection(conn);
} catch (cause) {
- console.error(LOG_TAG, "Tcp connection throws an error.", cause);
+ console.error(LOG_TAG, "Tcp connection throws an error:", cause);
}
}
}