0

Send email through smtp

by
Published Sep 21, 2023

Sends mail through smtp using the popular nodemailer library and the bun runtime. Supports html in the data field. Originally made to palliate to problems with Deno's integrated smtp module.

Script smtp
  • Submitted by aurélien brabant550 Bun
    Created 992 days ago
    1
    import * as nodemailer from 'nodemailer'
    2
    
    
    3
    export interface Smtp {
    4
      host: string;
    5
      port: number;
    6
      user: string;
    7
      password: string;
    8
    }
    9
    
    
    10
    export async function main(
    11
      smtp: Smtp,
    12
      from: string,
    13
      to: string,
    14
      subject: string,
    15
      data: string
    16
    ) {
    17
      const transport = nodemailer.createTransport({
    18
        host: smtp.host,
    19
        port: smtp.port,
    20
        auth: {
    21
          user: smtp.user,
    22
          pass: smtp.password
    23
        }
    24
      })
    25
    
    
    26
      const result = await transport.sendMail({
    27
        from,
    28
        to,
    29
        html: data,
    30
        subject
    31
      });
    32
    
    
    33
      return result;
    34
    }
    35