You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python调用AWS SES发送多收件人邮件时遇非法地址错误求助

Fixing the "Illegal address" Error in AWS SES Python Code

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

  1. Remove the unnecessary join call
    Just pass your original recipients list directly to ToAddresses:

    'ToAddresses': recipients,
    
  2. Fix the sender address format
    Your sender string uses HTML escape characters (&lt; and &gt;) 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.com if you haven't verified it yet).
  • Double-check that your AWS credentials have the ses:SendEmail permission attached.
  • Confirm your AWS_REGION matches the one where your SES identities are verified.

That should get your emails sending without the illegal address error!

内容的提问来源于stack exchange,提问作者snehil singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:19:54