0

我正在使用 SES 服务发送批量模板化的电子邮件。我对 SES 所做的事情感到困惑。它给了我发送电子邮件的成功响应。这是我得到的输出。

您可以在图像上看到“已发送”消息

在此处输入图像描述

这是代码,你可以看到,我已经成功返回了“Sent”字符串。我有一份准确的目的地清单。但是没有人收到电子邮件。

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

请告诉我可能的原因是什么,我试图找出解决方案,但找不到一个解决方案。

运行良好的代码。
# 尝试发送电子邮件。

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'])
4

0 回答 0