Amazon web services 如何通过AWS SES向多个收件人发送电子邮件

Amazon web services 如何通过AWS SES向多个收件人发送电子邮件,amazon-web-services,python-3.7,amazon-ses,Amazon Web Services,Python 3.7,Amazon Ses,大家好,我正在尝试使用Python通过AWS SES向多个用户发送电子邮件,但每当我尝试发送邮件时,我都会收到一个错误:非法地址 这是我的代码: def emailServiceForCustomerInformation(self, emailSubject, customerLicenseMessage, installation_name): # logger = ToolsLogger.getOrCreateLogger(current_user.keyspace) lo

大家好,我正在尝试使用Python通过AWS SES向多个用户发送电子邮件,但每当我尝试发送邮件时,我都会收到一个错误:非法地址

这是我的代码:

def emailServiceForCustomerInformation(self, emailSubject, customerLicenseMessage, installation_name):
    # logger = ToolsLogger.getOrCreateLogger(current_user.keyspace)
    logger = ToolsLogger.getOrCreateRootLogger()

    logger.info("Email service For Customer is started")

      record = int(recordCount)
    # print("emailRcord-",record)

    # This address must be verified with Amazon SES.
    SENDER = "Snehil singh<snehil@codedata.io>"

    # is still in the sandbox, this address must be verified.

    recipients = ["cosmoandysysmo@gmail.com","snehil@codedata.io"]
    RECIPIENT = ", ".join(recipients)

    # If necessary, replace us-east-1 with the AWS Region currently using for Amazon SES.
    AWS_REGION = "us-east-1"

    # The subject line for the email.
    SUBJECT = emailSubject

    BODY_TEXT = (customerLicenseMessage + ' ''For InstallationName-'+ installation_name)

    # The character encoding for the email.
    CHARSET = "UTF-8"

    client = boto3.client('ses', region_name=AWS_REGION,
                          aws_access_key_id=config[os.environ['CONFIG_TYPE']].S3_ACCESS_KEY,
                          aws_secret_access_key=config[os.environ['CONFIG_TYPE']].S3_ACCESS_SECRET_KEY,
                          config=Config(signature_version='s3v4'))

    is_success = True
    # Try to send the email.
    try:
        # Provide the contents of the email.
        response = client.send_email(
            Destination={
                'ToAddresses': [
                    RECIPIENT,
                ],
            },
            Message={
                'Body': {
                    'Text': {
                        'Charset': CHARSET,
                        'Data': BODY_TEXT,
                    },
                },
                'Subject': {
                    'Charset': CHARSET,
                    'Data': SUBJECT,
                },
            },
            Source=SENDER,
            # If you are not using a configuration set, comment or delete the
            # following line
            #         ConfigurationSetName=CONFIGURATION_SET,
        )
    # Display an error if something goes wrong.
    except ClientError as e:
        logger.exception(e)
        print(e.response['Error']['Message'])
        is_success = False
    else:
        # print("Email sent! Message ID:"),
        # print(response['MessageId'])
        logger.info("Email service is Completed and send to the mail")

    return is_success
def emailServiceForCustomerInformation(self、emailSubject、customerLicenseMessage、安装名称):
#logger=ToolsLogger.getOrCreateLogger(当前用户.keyspace)
logger=ToolsLogger.getOrCreateRootLogger()
logger.info(“为客户启动电子邮件服务”)
记录=int(记录计数)
#打印(“emailRcord-”,记录)
#必须通过Amazon SES验证此地址。
发件人=“斯奈希尔·辛格”
#仍在沙箱中,必须验证此地址。
收件人=[”cosmoandysysmo@gmail.com","snehil@codedata.io"]
收件人=“,”。加入(收件人)
#如有必要,将us-east-1替换为当前用于亚马逊SES的AWS地区。
AWS_REGION=“美国东部-1”
#电子邮件的主题行。
主题=电子邮件主题
BODY_TEXT=(customerLicenseMessage+''用于InstallationName-'+installation_name)
#电子邮件的字符编码。
CHARSET=“UTF-8”
客户机=boto3。客户机('ses',区域名称=AWS\U区域,
aws_access_key_id=config[os.environ['config_TYPE']].S3_access_key,
aws_secret_access_key=config[os.environ['config_TYPE']].S3_access_secret_key,
config=config(签名\u version='s3v4'))
成功是真的吗
#尝试发送电子邮件。
尝试:
#提供电子邮件的内容。
响应=client.send_电子邮件(
目的地={
“ToAddresss”:[
收件人
],
},
信息={
“身体”:{
“文本”:{
“字符集”:字符集,
“数据”:正文文本,
},
},
“主题”:{
“字符集”:字符集,
“数据”:主题,
},
},
来源=发送方,
#如果未使用配置集,请注释或删除
#下线
#ConfigurationSetName=配置集合,
)
#如果出现错误,则显示错误。
除ClientError作为e外:
记录器.异常(e)
打印(例如响应['Error']['Message'])
成功=错误吗
其他:
#打印(“已发送电子邮件!邮件ID:”),
#打印(响应['MessageId'])
logger.info(“电子邮件服务已完成并发送到邮件”)
回报就是成功
我在网上搜索过,但没有找到答案。这是我尝试过的另一种方法,但也没有帮助。请帮助我哪里做错了。我在哪里修改它?如果您有任何与此相关的问题,请ping我…提前感谢。

中:

如果你读了,它会告诉你:


总之:不要加入地址来构造收件人。收件人需要是字符串数组(Python中的列表),其中每个字符串都是一个电子邮件地址。

在我看来,您应该传入“收件人”,而不是收件人字符串。试着这样做:

Destination={'ToAddresses':recipients}

它似乎需要一个数组,而不是逗号分隔的字符串列表。

收件人必须是字符串数组>['email1','email2']

和>>

Destination={
            'ToAddresses': [
                RECIPIENT,
            ],
        },


thnx表示解决方案F.Duran thnx表示答案
Destination={'ToAddresses':recipients}
Destination={
            'ToAddresses': [
                RECIPIENT,
            ],
        },
Destination={
            'ToAddresses': RECIPIENT
        },