要使用AWS SES Python SDK发送多个收件人的电子邮件,你可以使用send_email()
方法并在Destination
参数中提供多个收件人的列表。以下是一个示例代码:
import boto3
# 创建SES客户端
ses_client = boto3.client('ses', region_name='us-west-2') # 替换为你的区域
# 定义发件人、收件人和邮件主题
sender = 'sender@example.com'
recipients = ['recipient1@example.com', 'recipient2@example.com'] # 添加所有收件人的电子邮件地址
subject = 'Test Email'
# 定义邮件内容
body = {
'Text': {
'Data': 'Hello, this is a test email'
}
}
# 发送邮件
response = ses_client.send_email(
Source=sender,
Destination={
'ToAddresses': recipients
},
Message={
'Subject': {
'Data': subject
},
'Body': body
}
)
print(response)
在上面的代码中,我们首先创建了一个SES客户端,然后定义了发件人、收件人和邮件主题。接下来,我们定义了邮件内容,这里只包含了一个简单的文本消息。最后,我们调用send_email()
方法,并在Destination
参数中提供了一个包含所有收件人的电子邮件地址的列表。
请注意,你需要将上述代码中的sender@example.com
和recipient1@example.com
、recipient2@example.com
替换为实际的电子邮件地址。
希望这个示例能帮到你!