[英]How to send a email to multiple email address using SES in Lambda function python
我正在尝试将事件驱动的邮件通知发送给所有订阅邮件通知的人。
这是我的代码。
import json
import boto3
import uuid
def lambda_handler(event, context):
item = json.loads(event['body'])
amount = item['bid_amount']
broker = item['posted_by_company']
email = ["sumanth@xxxxxxx", "sumanthshetty@gmail.com"]
email = ','.join(email)
print (type(email))
ses = boto3.client("ses")
try:
response = ses.send_email(
Source = "xxxxxx@xxxxxx",
Destination={
'ToAddresses': [
email
],
'CcAddresses': [
]
},
Message={
'Subject': {
'Data': "Your Bid has been Accepted"
},
'Body': {
'Text': {
'Data': "Your Bid of amount $"+ amount +" has been accepted by " + broker + "\n"+
"Here are the Load details:\n" +
"Load ID: \n" +
"Posted by: \n"
}
}
}
)
return {
'statusCode': 200,
'headers': {"Access-Control-Allow-Origin": "*"},
'body': json.dumps('e-mail sent ')
}
except Exception as e:
print(e)
return {
'statusCode': 500,
'headers': {"Access-Control-Allow-Origin": "*"},
'body': json.dumps('Error occured while sending an Bid e-mail')
}
似乎地址只需要一个字符串 object。如何将事件收到的所有电子邮件传递到地址中。?
如果你的email
实际上有你写的如下形式:
email = ["sumanth@xxxxxxx", "sumanthshetty@gmail.com"]
那么你可以直接传递它:
Destination={
'ToAddresses': email,
不需要email = ','.join(email)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.