2 Answers
- Newest
- Most votes
- Most comments
1
Yes it does indeed! SES is built specifically for this. If you are using python as IO showed above here are some you can look at:
- Jinja2: Jinja2 is a powerful and widely used templating engine for Python. It provides a flexible syntax for creating dynamic HTML templates. You can use Jinja2 to define your email templates and easily render them with dynamic data in your Python code.
- Mako: Mako is another templating engine for Python that allows you to create HTML templates. It provides a concise and easy-to-use syntax for generating dynamic content. Mako templates can be used to create email templates and render them with your Python code.
- Django Templates: If you're already familiar with Django, you can leverage its template system for creating email templates. Django provides a robust and feature-rich template engine that can be used outside of the Django web framework as well. You can use Django templates to define your email templates and render them using Django's template rendering API.
- Handlebars: Handlebars is a popular templating language that can be used with various programming languages, including Python. It provides a simple syntax for creating HTML templates. You can use a Python library like pybars3 to render Handlebars templates with dynamic data.
Let me know if these solve the issue or I can keep tracking it unless you accept one of these as working answer on your side.
-Zac
answered 10 months ago
1
Not sure if you had any more constraints on the problem, but I think you could build a solution from SES and Lambda. One possible workflow could be:
- Generate Personalized PDFs: Use whatever method you have for generating these PDFs and store each PDF in an S3 bucket with a filename that corresponds to the recipient's email address or other unique identifier. This way, you can programmatically associate each recipient with their specific PDF.
- Create a Recipient List: You'll need a list of recipients and the corresponding S3 links for their PDFs. This list can be an Excel sheet, CSV file, or a database table, whatever works best for you.
- Use Lambda to Send Emails: Create a Lambda function that will read from your recipient list, pull the appropriate PDF from S3, and then use SES to send the email.
Lambda could look something like this:
import boto3
import botocore
ses = boto3.client('ses')
s3 = boto3.resource('s3')
def send_email_with_pdf(recipient, pdf_filename):
try:
# Get PDF from S3
bucket_name = 'your-bucket-name'
s3_object = s3.Object(bucket_name, pdf_filename)
pdf_file = s3_object.get()['Body'].read()
# Create SES email
email = {
'Source': 'your-email@example.com',
'Destination': {
'ToAddresses': [recipient],
},
'Message': {
'Subject': {
'Data': 'Your Subject',
},
'Body': {
'Html': {
'Data': 'Your Email Body',
}
}
},
'Attachments': [{
'Name': pdf_filename,
'Data': pdf_file,
'ContentType': 'application/pdf',
}]
}
# Send SES email
ses.send_email(**email)
except botocore.exceptions.ClientError as e:
print(e.response['Error']['Message'])
else:
print(f'Email sent to {recipient}!')
def lambda_handler(event, context):
# This part depends on how your recipient list is stored
# But you want to loop through each recipient
for recipient in recipients:
# Retrieve their PDF filename from your data storage
pdf_filename = get_pdf_filename_for_recipient(recipient)
# Send them an email with their PDF
send_email_with_pdf(recipient, pdf_filename)
answered 10 months ago
Relevant content
- asked 5 months ago
- asked a year ago
- asked 10 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
Hi Zac, Thank you very much for your response and helpful feedback. This would work well and we will definately try.
Do you know if the ability to send personalised attachments in bulk will work with AWS? I.e can SES handle bulk sends with personalised attachments?