使用Python调用AWS SES发送多收件人邮件时遇非法地址错误求助
Hey there, let's break down why you're hitting that "Illegal address" error and fix it up quickly.
The Core Issue
Looking at your code, the main problem is how you're passing recipient addresses to SES:
recipients = ["cosmoandysysmo@gmail.com","snehil@codedata.io"] RECIPIENT = ", ".join(recipients) # Then later... 'ToAddresses': [ RECIPIENT, ],
AWS SES's send_email API expects ToAddresses to be a list of individual email address strings, not a single string with multiple addresses separated by commas. When you pass that joined string, SES treats the entire thing as one invalid email address, hence the error.
Quick Fixes
Remove the unnecessary
joincall
Just pass your originalrecipientslist directly toToAddresses:'ToAddresses': recipients,Fix the sender address format
Your sender string uses HTML escape characters (<and>) instead of actual angle brackets. Replace those with<and>so SES can parse the sender correctly:SENDER = "Snehil singh <snehil@codedata.io>"
Modified Code Snippet
Here's how the corrected send_email call should look:
response = client.send_email( Destination={ 'ToAddresses': recipients, # Use the original list directly }, Message={ 'Body': { 'Text': { 'Charset': CHARSET, 'Data': BODY_TEXT, }, }, 'Subject': { 'Charset': CHARSET, 'Data': SUBJECT, }, }, Source="Snehil singh <snehil@codedata.io>", # Fixed sender format # ConfigurationSetName=CONFIGURATION_SET, )
Additional Checks to Rule Out Other Issues
- If your AWS SES account is still in sandbox mode, all recipient addresses must be verified in SES (including
cosmoandysysmo@gmail.comif you haven't verified it yet). - Double-check that your AWS credentials have the
ses:SendEmailpermission attached. - Confirm your
AWS_REGIONmatches the one where your SES identities are verified.
That should get your emails sending without the illegal address error!
内容的提问来源于stack exchange,提问作者snehil singh

