0
send an email with aws ses
One script reply has been approved by the moderators Verified

send a mail with aws simple email service (ses).

More info: https://docs.aws.amazon.com/ses/latest/dg/send-email-api.html

Created by sindre svendby964 579 days ago Viewed 9604 times
0
Submitted by sindre svendby964 Deno
Verified 579 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/aws_api@v0.8.1/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