使用Amazon SES发送邮件之前,您需要验证您要发送邮件的电子邮件地址或域名。只有通过验证的电子邮件地址或域名才能发送邮件。
以下是一个使用Amazon SES发送电子邮件的Python代码示例:
import boto3
# Create an SES client
ses_client = boto3.client('ses', region_name='us-west-2')
# Verify an email address
response = ses_client.verify_email_identity(
EmailAddress='your-email@example.com'
)
# Send an email
response = ses_client.send_email(
Source='your-email@example.com',
Destination={
'ToAddresses': ['recipient@example.com']
},
Message={
'Subject': {
'Data': 'Hello from Amazon SES'
},
'Body': {
'Text': {
'Data': 'This email was sent using Amazon SES'
}
}
}
)
在上面的示例中,我们首先使用verify_email_identity方法验证要发送邮件的电子邮件地址。如果验证成功,我们可以使用send_email方法发送电子邮件。
请注意,在使用此代码之前,您需要安装并配置AWS SDK for Python(Boto3),并具有适当的AWS凭证。
确保将your-email@example.com替换为您的有效电子邮件地址,并将recipient@example.com替换为您要发送邮件的收件人的有效电子邮件地址。
这样,您可以确保只有经过验证的电子邮件地址或域名才能使用Amazon SES发送邮件。