add emailing logic
This commit is contained in:
parent
16bcfd9bf3
commit
431c184690
1 changed files with 28 additions and 0 deletions
28
src/email.ts
Normal file
28
src/email.ts
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue