From 431c18469024c030f3eca7e68e5898b0df927f02 Mon Sep 17 00:00:00 2001 From: Matthieu Jolimaitre Date: Fri, 2 Feb 2024 12:57:19 +0100 Subject: [PATCH] add emailing logic --- src/email.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/email.ts diff --git a/src/email.ts b/src/email.ts new file mode 100644 index 0000000..71501ed --- /dev/null +++ b/src/email.ts @@ -0,0 +1,28 @@ +import { SmtpClient } from "https://deno.land/x/smtp@v0.7.0/mod.ts"; + +export type EmailerConfig = { + hostname: string; + port: number; + username: string; + password: string; +}; + +export class Emailer { + private client; + private config; + private sender_email; + + public constructor(config: EmailerConfig, sender_email: string) { + this.config = config; + this.sender_email = sender_email; + this.client = new SmtpClient(); + } + + public async send(to_email: string, subject: string, content: string) { + const from = this.sender_email; + const to = to_email; + await this.client.connectTLS(this.config); + await this.client.send({ from, to, subject, content }); + await this.client.close(); + } +}