-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathses.ts
266 lines (250 loc) · 8.17 KB
/
ses.ts
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import { SendRawEmailCommand } from "@aws-sdk/client-ses";
import { encode } from "base64-arraybuffer";
import { AvailableSQSFunctions, SQSPayload } from "common/types/sqsMessage.js";
/**
* Generates a SendRawEmailCommand for SES to send an email with an attached membership pass.
*
* @param recipientEmail - The email address of the recipient.
* * @param recipientEmail - The email address of the sender with a verified identity in SES.
* @param attachmentBuffer - The membership pass in ArrayBufferLike format.
* @returns The command to send the email via SES.
*/
export function generateMembershipEmailCommand(
recipientEmail: string,
senderEmail: string,
attachmentBuffer: ArrayBufferLike,
): SendRawEmailCommand {
const encodedAttachment = encode(attachmentBuffer);
const boundary = "----BoundaryForEmail";
const emailTemplate = `
<!doctype html>
<html>
<head>
<title>Your ACM @ UIUC Membership</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<base target="_blank">
<style>
body {
background-color: #F0F1F3;
font-family: 'Helvetica Neue', 'Segoe UI', Helvetica, sans-serif;
font-size: 15px;
line-height: 26px;
margin: 0;
color: #444;
}
.wrap {
background-color: #fff;
padding: 30px;
max-width: 525px;
margin: 0 auto;
border-radius: 5px;
}
.button {
background: #0055d4;
border-radius: 3px;
text-decoration: none !important;
color: #fff !important;
font-weight: bold;
padding: 10px 30px;
display: inline-block;
}
.button:hover {
background: #111;
}
.footer {
text-align: center;
font-size: 12px;
color: #888;
}
img {
max-width: 100%;
height: auto;
}
a {
color: #0055d4;
}
a:hover {
color: #111;
}
@media screen and (max-width: 600px) {
.wrap {
max-width: auto;
}
}
</style>
</head>
<body>
<div class="gutter" style="padding: 30px;"> </div>
<img src="https://acm-brand-images.s3.amazonaws.com/banner-blue.png" style="height: 100px; width: 210px; align-self: center;"/>
<br />
<div class="wrap">
<h2 style="text-align: center;">Welcome</h2>
<p>
Thank you for becoming a member of ACM @ UIUC! Attached is your membership pass.
You can add it to your Apple or Google Wallet for easy access.
</p>
<p>
If you have any questions, feel free to contact us at
<a href="mailto:[email protected]">[email protected]</a>.
</p>
<p>
We also encourage you to check out our resources page, where you can find the benefits associated with your membership.
Welcome to ACM @ UIUC!
</p>
<div style="text-align: center; margin-top: 20px;">
<a href="https://www.acm.illinois.edu/resources" class="button">ACM @ UIUC Resources</a>
</div>
</div>
<div class="footer">
<p>
<a href="https://acm.illinois.edu">ACM @ UIUC Homepage</a>
<a href="mailto:[email protected]">Email ACM @ UIUC</a>
</p>
</div>
</body>
</html>
`;
const rawEmail = `
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="${boundary}"
From: ACM @ UIUC <${senderEmail}>
To: ${recipientEmail}
Subject: Your ACM @ UIUC Membership
--${boundary}
Content-Type: text/html; charset="UTF-8"
${emailTemplate}
--${boundary}
Content-Type: application/vnd.apple.pkpass
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="membership.pkpass"
${encodedAttachment}
--${boundary}--`.trim();
return new SendRawEmailCommand({
RawMessage: {
Data: new TextEncoder().encode(rawEmail),
},
});
}
/**
* Generates a SendRawEmailCommand for SES to send a sales confirmation email
*
* @param payload - The SQS Payload for sending sale emails
* @param senderEmail - The email address of the sender with a verified identity in SES.
* @param imageBuffer - The normal image ticket/pass in ArrayBufferLike format.
* @returns The command to send the email via SES.
*/
export function generateSalesEmail(
payload: SQSPayload<AvailableSQSFunctions.SendSaleEmail>["payload"],
senderEmail: string,
imageBuffer: ArrayBufferLike,
): SendRawEmailCommand {
const encodedImage = encode(imageBuffer);
const boundary = "----BoundaryForEmail";
const subject = `Your ${payload.type === "merch" ? "order" : "ticket"} has been confirmed!`;
const emailTemplate = `
<!doctype html>
<html>
<head>
<title>${subject}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<base target="_blank">
<style>
body {
background-color: #F0F1F3;
font-family: 'Helvetica Neue', 'Segoe UI', Helvetica, sans-serif;
font-size: 15px;
line-height: 26px;
margin: 0;
color: #444;
}
.wrap {
background-color: #fff;
padding: 30px;
max-width: 525px;
margin: 0 auto;
border-radius: 5px;
}
.button {
background: #0055d4;
border-radius: 3px;
text-decoration: none !important;
color: #fff !important;
font-weight: bold;
padding: 10px 30px;
display: inline-block;
}
.button:hover {
background: #111;
}
.footer {
text-align: center;
font-size: 12px;
color: #888;
}
img {
max-width: 100%;
height: auto;
}
a {
color: #0055d4;
}
a:hover {
color: #111;
}
@media screen and (max-width: 600px) {
.wrap {
max-width: auto;
}
}
</style>
</head>
<body>
<div class="gutter" style="padding: 30px;"> </div>
<img src="https://acm-brand-images.s3.amazonaws.com/banner-blue.png" style="height: 100px; width: 210px; align-self: center;"/>
<br />
<div class="wrap">
<h2 style="text-align: center;">${subject}</h2>
<p>
Thank you for your purchase of ${payload.quantity} ${payload.itemName} ${payload.size ? `(size ${payload.size})` : ""}.
${payload.type === "merch" ? "When picking up your order" : "When attending the event"}, show the attached QR code to our staff to verify your purchase.
</p>
${payload.customText ? `<p>${payload.customText}</p>` : ""}
<p>
If you have any questions, feel free to ask on our Discord!
</p>
<div style="text-align: center; margin-top: 20px;">
<a href="https://go.acm.illinois.edu/discord" class="button">Join our Discord</a>
</div>
</div>
<div class="footer">
<p>
<a href="https://acm.illinois.edu">ACM @ UIUC Homepage</a>
<a href="mailto:[email protected]">Email ACM @ UIUC</a>
</p>
</div>
</body>
</html>
`;
const rawEmail = `
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="${boundary}"
From: ACM @ UIUC <${senderEmail}>
To: ${payload.email}
Subject: Your ACM @ UIUC Purchase
--${boundary}
Content-Type: text/html; charset="UTF-8"
${emailTemplate}
--${boundary}
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="${payload.itemName}.png"
${encodedImage}
--${boundary}--`.trim();
return new SendRawEmailCommand({
RawMessage: {
Data: new TextEncoder().encode(rawEmail),
},
});
}