I'm using Amazon's Simple Email Service to send transactional emails. To do so, I created a Python class that uses the AWS SDK for Python, Boto3.
One of the parameters of this class, recipients, represents a list of recipients who will receive the emails. I created a configuration set with the "ses: from-domain" auto-tag and established that the collected metrics will be sent to the CloudWatch service.
With this setting, I can check the number of recipients who opened the emails, clicked on the contained links, or faced rendering failure. However, these values are presented in aggregate form.
I would like to know how:
1.Use the configuration set to collect metrics for each individual recipient (email address); 2.Integrate that configuration into the method I'm using to send emails or the HTML code that constitutes the email. Since I currently use the auto-tag feature, it only needs the configSetName on my code.
Method for sending emails:
def send_email(self, subject, charset="UTF-8"):
"""
"""
# Create a new SES resource and specify a region.
client = boto3.client('ses',region_name=self._aws_region)
# Try to send the email.
try:
#Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': self._recipient,
},
Message={
'Body': {
'Html': {
'Charset': charset,
'Data': self._html_content.getvalue(),
},
},
'Subject': {
'Charset': charset,
'Data': subject,
},
},
Source=self.sender,
# If you are not using a configuration set, comment or delete the
# following line
ConfigurationSetName="test",
)
# Display an error if something goes wrong.
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:"),
print(response['ResponseMetadata']['RequestId'])