|
| 1 | +import { SendRawEmailCommand } from "@aws-sdk/client-ses"; |
| 2 | +import { encode } from "base64-arraybuffer"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Generates a SendRawEmailCommand for SES to send an email with an attached membership pass. |
| 6 | + * |
| 7 | + * @param recipientEmail - The email address of the recipient. |
| 8 | + * * @param recipientEmail - The email address of the sender with a verified identity in SES. |
| 9 | + * @param attachmentBuffer - The membership pass in ArrayBufferLike format. |
| 10 | + * @returns The command to send the email via SES. |
| 11 | + */ |
| 12 | +export function generateMembershipEmailCommand( |
| 13 | + recipientEmail: string, |
| 14 | + senderEmail: string, |
| 15 | + attachmentBuffer: ArrayBufferLike, |
| 16 | +): SendRawEmailCommand { |
| 17 | + const encodedAttachment = encode(attachmentBuffer); |
| 18 | + const boundary = "----BoundaryForEmail"; |
| 19 | + |
| 20 | + const emailTemplate = ` |
| 21 | +<!doctype html> |
| 22 | +<html> |
| 23 | + <head> |
| 24 | + <title>Your ACM @ UIUC Membership</title> |
| 25 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 26 | + <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"> |
| 27 | + <base target="_blank"> |
| 28 | + <style> |
| 29 | + body { |
| 30 | + background-color: #F0F1F3; |
| 31 | + font-family: 'Helvetica Neue', 'Segoe UI', Helvetica, sans-serif; |
| 32 | + font-size: 15px; |
| 33 | + line-height: 26px; |
| 34 | + margin: 0; |
| 35 | + color: #444; |
| 36 | + } |
| 37 | + .wrap { |
| 38 | + background-color: #fff; |
| 39 | + padding: 30px; |
| 40 | + max-width: 525px; |
| 41 | + margin: 0 auto; |
| 42 | + border-radius: 5px; |
| 43 | + } |
| 44 | + .button { |
| 45 | + background: #0055d4; |
| 46 | + border-radius: 3px; |
| 47 | + text-decoration: none !important; |
| 48 | + color: #fff !important; |
| 49 | + font-weight: bold; |
| 50 | + padding: 10px 30px; |
| 51 | + display: inline-block; |
| 52 | + } |
| 53 | + .button:hover { |
| 54 | + background: #111; |
| 55 | + } |
| 56 | + .footer { |
| 57 | + text-align: center; |
| 58 | + font-size: 12px; |
| 59 | + color: #888; |
| 60 | + } |
| 61 | + img { |
| 62 | + max-width: 100%; |
| 63 | + height: auto; |
| 64 | + } |
| 65 | + a { |
| 66 | + color: #0055d4; |
| 67 | + } |
| 68 | + a:hover { |
| 69 | + color: #111; |
| 70 | + } |
| 71 | + @media screen and (max-width: 600px) { |
| 72 | + .wrap { |
| 73 | + max-width: auto; |
| 74 | + } |
| 75 | + } |
| 76 | + </style> |
| 77 | + </head> |
| 78 | +<body> |
| 79 | + <div class="gutter" style="padding: 30px;"> </div> |
| 80 | + <img src="https://acm-brand-images.s3.amazonaws.com/banner-blue.png" style="height: 100px; width: 210px; align-self: center;"/> |
| 81 | + <br /> |
| 82 | + <div class="wrap"> |
| 83 | + <h2 style="text-align: center;">Welcome</h2> |
| 84 | + <p> |
| 85 | + Thank you for becoming a member of ACM @ UIUC! Attached is your membership pass. |
| 86 | + You can add it to your Apple or Google Wallet for easy access. |
| 87 | + </p> |
| 88 | + <p> |
| 89 | + If you have any questions, feel free to contact us at |
| 90 | + |
| 91 | + </p> |
| 92 | + <div style="text-align: center; margin-top: 20px;"> |
| 93 | + <a href="https://acm.illinois.edu" class="button">Visit ACM @ UIUC</a> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + <div class="footer"> |
| 97 | + <p> |
| 98 | + <a href="https://acm.illinois.edu">ACM @ UIUC Homepage</a> |
| 99 | + <a href="mailto:[email protected]">Email ACM @ UIUC</a> |
| 100 | + </p> |
| 101 | + </div> |
| 102 | +</body> |
| 103 | +</html> |
| 104 | + `; |
| 105 | + |
| 106 | + const rawEmail = ` |
| 107 | +MIME-Version: 1.0 |
| 108 | +Content-Type: multipart/mixed; boundary="${boundary}" |
| 109 | +From: ACM @ UIUC <${senderEmail}> |
| 110 | +To: ${recipientEmail} |
| 111 | +Subject: Your ACM @ UIUC Membership |
| 112 | +
|
| 113 | +--${boundary} |
| 114 | +Content-Type: text/html; charset="UTF-8" |
| 115 | +
|
| 116 | +${emailTemplate} |
| 117 | +
|
| 118 | +--${boundary} |
| 119 | +Content-Type: application/vnd.apple.pkpass |
| 120 | +Content-Transfer-Encoding: base64 |
| 121 | +Content-Disposition: attachment; filename="membership.pkpass" |
| 122 | +
|
| 123 | +${encodedAttachment} |
| 124 | +--${boundary}--`.trim(); |
| 125 | + return new SendRawEmailCommand({ |
| 126 | + RawMessage: { |
| 127 | + Data: new TextEncoder().encode(rawEmail), |
| 128 | + }, |
| 129 | + }); |
| 130 | +} |
0 commit comments