0

send an email with aws ses

by
Published May 23, 2023

send a mail with aws simple email service (ses). More info: https://docs.aws.amazon.com/ses/latest/dg/send-email-api.html

Script aws-ses Verified

The script

Submitted by hugo989 Bun
Verified 17 days ago
1
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses@3";
2

3
// Create sendEmail params
4
type Aws = {
5
  awsAccessKeyId: string;
6
  awsSecretAccessKey: string;
7
  region: string;
8
};
9
export async function main(
10
  toAddresses: string[],
11
  htmlData: string,
12
  textData: string,
13
  subject: string,
14
  source: string,
15
  credentials: Aws,
16
) {
17
  var params = {
18
    Destination: {
19
      ToAddresses: toAddresses,
20
    },
21
    Message: {
22
      Body: {
23
        Html: {
24
          Charset: "UTF-8",
25
          Data: htmlData,
26
        },
27
        Text: {
28
          Charset: "UTF-8",
29
          Data: textData,
30
        },
31
      },
32
      Subject: {
33
        Charset: "UTF-8",
34
        Data: subject,
35
      },
36
    },
37
    Source: source /* required */,
38
  };
39

40
  // Create the SES service object
41
  const ses = new SESClient({
42
    credentials: {
43
      accessKeyId: credentials.awsAccessKeyId,
44
      secretAccessKey: credentials.awsSecretAccessKey,
45
    },
46
    region: credentials.region,
47
  });
48
  return await ses.send(new SendEmailCommand(params));
49
}
50

Other submissions
  • Submitted by sindre svendby964 Deno
    Created 409 days ago
    1
    import {
    2
      SendEmailRequest,
    3
      SES,
    4
    } from "https://aws-api.deno.dev/v0.4/services/ses.ts";
    5
    // import the base client library
    6
    import { ApiFactory } from "https://deno.land/x/[email protected]/client/mod.ts";
    7
    
    
    8
    // Create sendEmail params
    9
    type Aws = {
    10
      awsAccessKeyId: string;
    11
      awsSecretAccessKey: string;
    12
      region: string;
    13
    };
    14
    export async function main(
    15
      toAddresses: string[],
    16
      htmlData: string,
    17
      textData: string,
    18
      subject: string,
    19
      source: string,
    20
      credentials: Aws,
    21
    ) {
    22
      var params = {
    23
        Destination: {
    24
          ToAddresses: toAddresses,
    25
        },
    26
        Message: {
    27
          Body: {
    28
            Html: {
    29
              Charset: "UTF-8",
    30
              Data: htmlData,
    31
            },
    32
            Text: {
    33
              Charset: "UTF-8",
    34
              Data: textData,
    35
            },
    36
          },
    37
          Subject: {
    38
            Charset: "UTF-8",
    39
            Data: subject,
    40
          },
    41
        },
    42
        Source: source /* required */,
    43
      };
    44
    
    
    45
      // Create the promise and SES service object
    46
      const apiFac = new ApiFactory({
    47
        credentials: {
    48
          awsAccessKeyId: credentials.awsAccessKeyId,
    49
          awsSecretKey: credentials.awsSecretAccessKey,
    50
        },
    51
        region: credentials.region,
    52
      });
    53
      const ses = new SES(apiFac);
    54
      return await ses.sendEmail(params);
    55
    }
    56