如何在Lambda函数python中使用SES将电子邮件发送到多个电子邮件地址



我正在尝试将事件驱动的邮件通知发送给所有订阅邮件通知的人。

这是我的密码。

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')
}

它似乎只接收一个字符串对象。如何将事件收到的所有电子邮件传递到地址。?

如果您的email实际上具有您所写的以下形式:

email = ["sumanth@xxxxxxx", "sumanthshetty@gmail.com"]

然后你可以直接通过:

Destination={
'ToAddresses': email,

不需要email = ','.join(email)

相关内容

  • 没有找到相关文章

最新更新