Skip to content

Instantly share code, notes, and snippets.

@rajshah001
Created December 15, 2023 13:46
Show Gist options
  • Save rajshah001/714e98922ab4fcef77cde7968f39942e to your computer and use it in GitHub Desktop.
Save rajshah001/714e98922ab4fcef77cde7968f39942e to your computer and use it in GitHub Desktop.
recordBakeryOfferClickEvents
import boto3
import uuid
import json
# Create a boto3 client for SES
ses_client = boto3.client('ses')
def lambda_handler(event, context):
for record in event['Records']:
print(record)
# Extract attributes from the SQS record
sqs_body = json.loads(json.loads(record['body'])['Message'])
interest = sqs_body['mail']['tags']['Interest']
# message_id = sqs_body['mail']['messageId']
# event_type = sqs_body['eventType']
# timestamp = sqs_body['click']['timestamp']
# link = sqs_body['click']['link']
# user_mail = sqs_body['mail']['destination'][0]
# Activation
sender_email = "iambatmanbrucewayne6789@gmail.com"
recipient_email = "rajshah.comps@gmail.com"
subject = "Special Offer from Bakery Shop on Cookies"
html_body = """
<!DOCTYPE html>
<html lang="en" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<title></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/><!--[if mso]><xml><o:OfficeDocumentSettings><o:PixelsPerInch>96</o:PixelsPerInch><o:AllowPNG/></o:OfficeDocumentSettings></xml><![endif]-->
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
a[x-apple-data-detectors] {
color: inherit !important;
text-decoration: inherit !important;
}
#MessageViewBody a {
color: inherit;
text-decoration: none;
}
p {
line-height: inherit
}
.desktop_hide,
.desktop_hide table {
mso-hide: all;
display: none;
max-height: 0px;
overflow: hidden;
}
.image_block img+div {
display: none;
}
@media (max-width:620px) {
.desktop_hide table.icons-inner {
display: inline-block !important;
}
.icons-inner {
text-align: center;
}
.icons-inner td {
margin: 0 auto;
}
.mobile_hide {
display: none;
}
.row-content {
width: 100% !important;
}
.stack .column {
width: 100%;
display: block;
}
.mobile_hide {
min-height: 0;
max-height: 0;
max-width: 0;
overflow: hidden;
font-size: 0px;
}
.desktop_hide,
.desktop_hide table {
display: table !important;
max-height: none !important;
}
}
</style>
</head>
<body style="background-color: #FFFFFF; margin: 0; padding: 0; -webkit-text-size-adjust: none; text-size-adjust: none;">
<table border="0" cellpadding="0" cellspacing="0" class="nl-container" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #FFFFFF;" width="100%">
<tbody>
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" class="row row-1" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #a797ff;" width="100%">
<tbody>
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" class="row-content stack" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #afa2f2; color: #000000; width: 600px; margin: 0 auto;" width="600">
<tbody>
<tr>
<td class="column column-1" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;" width="100%">
<table border="0" cellpadding="10" cellspacing="0" class="heading_block block-1" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="pad">
<h1 style="margin: 0; color: #7747FF; direction: ltr; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 38px; font-weight: 700; letter-spacing: normal; line-height: 120%; text-align: left; margin-top: 0; margin-bottom: 0; mso-line-height-alt: 45.6px;"><span class="tinyMce-placeholder">Bakery Shop : Exclusive Offer</span></h1>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="image_block block-2" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="pad" style="width:100%;">
<div align="center" class="alignment" style="line-height:10px">
<div style="max-width: 600px;"><img alt="Image" src="https://i.postimg.cc/9M088ZpB/AP-Header.jpg" style="display: block; height: auto; border: 0; width: 100%;" title="Image" width="600"/></div>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="10" cellspacing="0" class="divider_block block-3" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="pad">
<div align="center" class="alignment">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="divider_inner" style="font-size: 1px; line-height: 1px; border-top: 0px solid #FFFFFF;"><span> </span></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="paragraph_block block-4" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;" width="100%">
<tr>
<td class="pad" style="padding-bottom:30px;padding-left:20px;padding-right:20px;">
<div style="color:#FFFFFF;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:16px;line-height:180%;text-align:center;mso-line-height-alt:28.8px;">
<p style="margin: 0; word-break: break-word;"><span>Curabitur bibendum est sit amet quam porta vulputate. Nam luctus fermentum lectus ut egestas. Nullam vehicula sem sed bibendum placerat. Ut risus nibh, dictum varius maximus et, bibendum eu est. Duis posuere, odio sit amet mollis congue, dolor lacus fringilla nibh luctus fermentum lectus ut egestas. </span></p>
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table align="center" border="0" cellpadding="0" cellspacing="0" class="row row-2" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #eddfd7;" width="100%">
<tbody>
<tr>
<td>
<table align="center" border="0" cellpadding="0" cellspacing="0" class="row-content stack" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #DECEBA; color: #333; width: 600px; margin: 0 auto;" width="600">
<tbody>
<tr>
<td class="column column-1" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;" width="50%">
<table border="0" cellpadding="0" cellspacing="0" class="image_block block-1" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="pad" style="padding-bottom:30px;padding-left:20px;padding-right:20px;padding-top:30px;width:100%;">
<div align="center" class="alignment" style="line-height:10px">
<div style="max-width: 260px;"><img alt="Image" src="https://i.postimg.cc/KYJpDJnz/AP-3.jpg" style="display: block; height: auto; border: 0; width: 100%;" title="Image" width="260"/></div>
</div>
</td>
</tr>
</table>
</td>
<td class="column column-2" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; font-weight: 400; text-align: left; padding-bottom: 5px; padding-top: 5px; vertical-align: top; border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px;" width="50%">
<table border="0" cellpadding="0" cellspacing="0" class="paragraph_block block-1" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;" width="100%">
<tr>
<td class="pad" style="padding-bottom:20px;padding-left:20px;padding-right:20px;padding-top:30px;">
<div style="color:#352220;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:14px;line-height:120%;text-align:left;mso-line-height-alt:16.8px;">
<p style="margin: 0; word-break: break-word;"><strong>CHEAP & CHEERFUL</strong></p>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="paragraph_block block-2" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;" width="100%">
<tr>
<td class="pad" style="padding-left:20px;padding-right:20px;">
<div style="color:#352220;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:24px;line-height:120%;text-align:left;mso-line-height-alt:28.799999999999997px;">
<p style="margin: 0; word-break: break-word;"><span><span>BLUEBERRY COOKIES</span></span></p>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="20" cellspacing="0" class="paragraph_block block-3" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt; word-break: break-word;" width="100%">
<tr>
<td class="pad">
<div style="color:#352220;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:16px;line-height:180%;text-align:left;mso-line-height-alt:28.8px;">
<p style="margin: 0; word-break: break-word;"><span>$ 5.99</span></p>
<p style="margin: 0; word-break: break-word;"><span>Curabitur bibendum est sit amet quam porta vulputate. Nam luctus fermentum lectus ut egestas. Nullam vehicula sem sed bibendum placerat. Ut risus nibh, dictum varius maximus et, bibendum eu est. Duis posuere, odio sit amet mollis congue, dolor lacus fringilla .</span></p>
</div>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="button_block block-4" role="presentation" style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;" width="100%">
<tr>
<td class="pad" style="padding-bottom:30px;padding-left:20px;text-align:left;">
<div align="left" class="alignment"><!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" style="height:35px;width:128px;v-text-anchor:middle;" arcsize="12%" stroke="false" fillcolor="#484A57">
<w:anchorlock/>
<v:textbox inset="0px,0px,0px,0px">
<center style="color:#DECEBA; font-family:Arial, sans-serif; font-size:14px">
<![endif]-->
<div style="text-decoration:none;display:inline-block;color:#DECEBA;background-color:#484A57;border-radius:4px;width:auto;border-top:0px solid transparent;font-weight:undefined;border-right:0px solid transparent;border-bottom:0px solid transparent;border-left:0px solid transparent;padding-top:5px;padding-bottom:5px;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:14px;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:14px;display:inline-block;letter-spacing:normal;"><span style="word-break:break-word;"><span data-mce-style="" style="line-height: 25.2px;">ORDER NOW</span></span></span></div><!--[if mso]></center></v:textbox></v:roundrect><![endif]-->
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table><!-- End -->
</body>
</html>
"""
# Define the message structure
message = {
'Subject': {
'Data': subject,
'Charset': 'UTF-8'
},
'Body': {
'Html': {
'Data': html_body,
'Charset': 'UTF-8'
}
}
}
if 'Cookies' in interest:
# Send the email
ses_client.send_email(
Source=sender_email,
Destination={
'ToAddresses': [recipient_email]
},
Message=message
)
print(f"Sent HTML email to {recipient_email} with subject: {subject}")
return {
'statusCode': 200,
'body': 'Events ingested and messages deleted successfully.'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment