如何在 Lambda 函数中使用 SES 向多个电子邮件地址发送电子邮件 python
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')
}
地址似乎只需要一个字符串对象。
如何将事件收到的所有电子邮件传递到 toAddress。?
如果您的 email
实际上具有以下形式:
email = ["sumanth@xxxxxxx", "sumanthshetty@gmail.com"]
那你直接pass就可以了:
Destination={
'ToAddresses': email,
不需要 email = ','.join(email)
。
我正在尝试将事件驱动的邮件通知发送给所有订阅邮件通知的人。
这是我的代码。
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')
}
地址似乎只需要一个字符串对象。 如何将事件收到的所有电子邮件传递到 toAddress。?
如果您的 email
实际上具有以下形式:
email = ["sumanth@xxxxxxx", "sumanthshetty@gmail.com"]
那你直接pass就可以了:
Destination={
'ToAddresses': email,
不需要 email = ','.join(email)
。