0

Send Email

by
Published Aug 16, 2022

Send an email using smtp

Script smtp Verified

The script

Submitted by hugo989 Bun
Verified 55 days ago
1
import nodemailer from "nodemailer";
2

3
export async function main(
4
  smtp_res: RT.Smtp,
5
  to_email: string,
6
  from_email: string,
7
  subject: string,
8
  content: string,
9
) {
10
  const transporter = nodemailer.createTransport({
11
    host: smtp_res.host,
12
    port: smtp_res.port,
13
    secure: smtp_res.port === 465,
14
    auth: {
15
      user: smtp_res.user,
16
      pass: smtp_res.password,
17
    },
18
  });
19

20
  await transporter.sendMail({
21
    from: from_email,
22
    to: to_email,
23
    subject: subject,
24
    text: content,
25
  });
26

27
  return `Email sent from ${from_email} to ${to_email}`;
28
}
Other submissions
  • Submitted by admin Deno
    Created 398 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