-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.js
More file actions
114 lines (104 loc) · 2.58 KB
/
send_email.js
File metadata and controls
114 lines (104 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import AWS from 'aws-sdk@^2'
export default {
name: "Send Email",
description: "Send an email, with or without an attachment",
key: "send_email",
version: "0.1.3",
type: "action",
props: {
amazon_ses: {
type: "app",
app: "amazon_ses",
},
to: {
type: "string",
label: "To Addresses",
description: "Comma-separated list of email addresses for the To email header."
},
from: {
type: "string",
label: "From Address"
},
subject: {
type: "string",
label: "Subject"
},
body: {
type: "string",
label: "Body",
description: "Plain-text message body."
},
attachmentFilename: {
type: "string[]",
label: "Attachment Filename",
optional: true
},
attachmentContent: {
type: "string[]",
label: "Attachment Content",
optional: true,
default: [],
},
attachmentType: {
type: "string[]",
label: "Attachment Content Type",
optional: true
},
attachmentEncoding: {
type: "string",
label: "Attachment Encoding",
default: "BASE64",
optional: true
},
skip: {
type: "boolean",
label: "Skip",
description: "Set Skip to TRUE or an expression that evaluates to true to skip this step.",
default: false,
optional: true,
}
},
async run({ steps, $ }) {
if (this.skip) {
$.export("$summary", `Skipped`)
return {}
}
const { accessKeyId, secretAccessKey } = this.amazon_ses.$auth
const ses = new AWS.SES({
accessKeyId,
secretAccessKey,
region: 'us-east-1',
})
const boundary = "----=_Part_123456"
const emailArray = [
`From: ${this.from}`,
`To: ${this.to}`,
"Subject: " + this.subject,
"MIME-Version: 1.0",
`Content-Type: multipart/mixed; boundary="${boundary}"`,
"",
`--${boundary}`,
"Content-Type: text/plain; charset=UTF-8",
"",
this.body,
"",
`--${boundary}`,
]
const rawEmail = emailArray.concat(this.attachmentContent.flatMap((content, i) => {
return [
`Content-Type: ${this.attachmentType[i]}; charset=UTF-8`,
`Content-Disposition: attachment; filename="${this.attachmentFilename[i]}"`,
`Content-Transfer-Encoding: ${this.attachmentEncoding || "base64"}`,
"",
content,
"",
`--${boundary}--`,
]
})).join("\n")
const params = {
RawMessage: { Data: Buffer.from(rawEmail) },
}
const result = await ses.sendRawEmail(params).promise()
return result
},
}