我们在 AWS Lambda 中循环访问 160 个电子邮件地址,并调用 SES 的 send_raw_email() API 调用,每次调用一个地址。 50 次循环后,我们收到错误“收件人计数超过 50”。但每个电话只有一个收件人。除了“收件人:”之外,电子邮件中的其他信息在通话之间是相同的。我们这样做是为了防止收件人看到其他收件人的地址。
电子邮件是否在 SES 批量处理? (我们怎么会达到这个限制?)
我们怎样才能克服这个错误?
添加代码:
for item in recipients['Items']:
RECIPIENT = item['email']['S']
msg['To'] = RECIPIENT
try:
#Provide the contents of the email.
response = ses.send_raw_email(
Source=SENDER,
Destinations=[
RECIPIENT
],
RawMessage={
'Data':msg.as_string(),
}
)
# Display an error if something goes wrong.
except ClientError as e:
print("failed to send email: ",e.response['Error']['Message'])
return {
'statusCode': 400,
'body': json.dumps(e.response['Error']['Message'])
}
else:
print("Email sent! Message ID:"),
print(response['MessageId'])