Send Email
One script reply has been approved by the moderators Verified

Send an email using smtp

Created by admin 1304 days ago Picked 189 times
Submitted by admin Deno
Verified 309 days ago
1
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts";
2

3
type Smtp = {
4
  host: string;
5
  port: number;
6
  user: string;
7
  password: string;
8
};
9
export async function main(
10
  smtp_res: Smtp,
11
  to_email: string,
12
  from_email: string,
13
  subject: string,
14
  content: string,
15
) {
16
  const client = new SmtpClient();
17

18
  await client.connectTLS({
19
      hostname: smtp_res.host,
20
      username: smtp_res.user,
21
      port: smtp_res.port,
22
      password: smtp_res.password
23
  });
24

25
  await client.send({
26
    from: from_email,
27
    to: to_email,
28
    subject: subject,
29
    content: content,
30
  });
31

32
  await client.close();
33
  return `Email sent from ${from_email} to ${to_email}`;
34
}
35