以下是一个Python代码示例,用于在AWS Lambda中发送电子邮件:
import boto3
SES_REGION = "us-west-2"
SENDER = "sender@example.com"
RECIPIENT = "recipient@example.com"
ses_client = boto3.client("ses", region_name=SES_REGION)
def lambda_handler(event, context):
SUBJECT = "Hello from AWS SES"
BODY_TEXT = "This email was sent using the AWS SES service."
BODY_HTML = "This email was sent using the AWS SES service.
"
try:
response = ses_client.send_email(
Destination={
"ToAddresses": [
RECIPIENT
]
},
Message={
"Body": {
"Html": {
"Charset": "UTF-8",
"Data": BODY_HTML
},
"Text": {
"Charset": "UTF-8",
"Data": BODY_TEXT
}
},
"Subject": {
"Charset": "UTF-8",
"Data": SUBJECT
}
},
Source=SENDER
)
print("Email sent. Message ID: ", response["MessageId"])
except Exception as e:
print("Email sending failed: ", e)
上一篇:AWSSES拦截列表问题