0

I am using SES service to send bulk-templated emails. I am confused about what the SES done. It gives me a success response in sending emails. Here is the output that I got.

You can see "Sent" message on image

enter image description here

and here is code, you can see, I have returned 'Sent' string on success. I had an accurate list of destinations. But no one receives an email.

import json
import time

def send_bulk_emails(template_name, destination_list):
    ses_client = session.client('ses')
    response = ses_client.send_bulk_templated_email(
       Source='registered-domain',
       Template=template_name,
       DefaultTags=[{'Name': 'X-SES-CONFIGURATION-SET','Value': 'xiq-track-events'},],
       DefaultTemplateData='{ \"name\":\"Alejandro\", \"favoriteanimal\": \"zebra\" }',
       Destinations= destination_list
  )

      if response['Status'][0]['Status'] == 'Success':
          return 'Sent'
      else:
          print('Error: ', response)
          return 'not Sent'


sqs = session.resource('sqs')
queue = sqs.Queue(
      'accurate-queue-url'
)    

 while True:
    messages = queue.receive_messages(
    MaxNumberOfMessages=10,
    WaitTimeSeconds = 10,
)
if len(messages) == 0:
    print("No messages to process, exiting ...")
    break
for item in messages:
    email_receivers = json.loads(item.body)
 #         for des in email_receivers['destinations']:
 #           des['ReplacementTemplateData'] = json.dumps(des['ReplacementTemplateData'])
    print('Template Name: ', email_receivers['template_name'])
    print('Destinations: ', email_receivers['destinations'])
    print(send_bulk_emails(email_receivers['template_name'], email_receivers['destinations']))  # it prints 'Sent' on success
    if send_bulk_emails(email_receivers['template_name'], email_receivers['destinations']) == 'Sent':
#             item.delete()
        print('item deleted')
    time.sleep(1)
break

Please tell me what could be the possible reason, I have tried to find out a solution but I could not find a single one.

Code that works fine.
# Try to send the email.

client = session.client('ses')

with open('C:\\Users\\user_name\\Documents\\complete.html', 'r') as content_file:
html_content = content_file.read()

# The HTML body of the email.
BODY_HTML = html_content

CHARSET = "UTF-8"

try:
    Provide the contents of the email.
    response = client.create_template(
    Template={
         'TemplateName': 'test-123123-123',
         'SubjectPart': 'Testing subject-5',
         'TextPart': 'dummy string',
         'HtmlPart': BODY_HTML
    }
  )

e_response = client.send_bulk_templated_email(
    Source='alikhalil@company.com',
    Template='test-123123-123',
    ReplyToAddresses=[
    'ali@test.com',
        'ali@example.com'
    ],
    DefaultTags=[{'Name': 'X-SES-CONFIGURATION-SET','Value': 'xiq-track-events'},],
    DefaultTemplateData='{ \"name\":\"Alejandro\", \"favoriteanimal\": \"zebra\" }',
    Destinations=[
       {
            'Destination': { 'ToAddresses': ['ali.test@gmail.com',] },
            'ReplacementTemplateData': '{ "first_name":"Ali_G", "last_name": "", "copmany_name": "", "u_designation": "", "unsubscribe_link": "http://example.com/workbench/unsubscriber/?buid=1538&contact_id=348203&email=alitest@gmail.com" }'            }

    ]

)
delete_template = client.delete_template(
    TemplateName = 'bulk_test_9'
)
# Display an error if something goes wrong.
    print('Emial response: ', e_response)
except ClientError as e:
    print (e)
    print(e.response['Error']['Message'])
  • check your source indentation. – Lamanus Sep 26 '19 at 22:13
  • 1
    you have problem in rendering, if rendering fails, you still get success from ses but it actually failed, you can enable SNS for rendering failure in configuration set and it will tell you the problem and also check the cloudwatch if you see any data points for rendering failure metric. – James Dean Sep 27 '19 at 03:56
  • @JamesDean Thank you for your suggestion. Here is another code (updated in actual question statement), that works fine. – ali khalil Sep 27 '19 at 07:59
  • @JamesDean can you tell me what could be the reason for rendering fail? – ali khalil Sep 27 '19 at 08:12
  • @alikhalil do you see anything in rendering failure metric or sns notification ? – James Dean Sep 27 '19 at 13:38
  • @JamesDean yes, I found. It was a rendering issue. There was a spelling mistake in templateData variable. – ali khalil Sep 30 '19 at 09:41

0 Answers0