add emailing logic

This commit is contained in:
Matthieu Jolimaitre 2024-02-02 12:57:19 +01:00
parent 16bcfd9bf3
commit 431c184690

28
src/email.ts Normal file
View file

@ -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();
}
}