微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过Amazon SES向多个人发送电子邮件时发生AttributeError

如何解决通过Amazon SES向多个人发送电子邮件时发生AttributeError

我的目标是向多个收件人发送电子邮件。当我只在RECIPIENT变量中给一封电子邮件并提供Destinations = [RECIPIENT]时,代码将运行,但是当我使用以下代码给多封电子邮件时,它将给出错误
“ AttributeError:'list'对象没有属性'encode'” 任何指针都值得赞赏。

RECIPIENT = "abc@xyz.com efg@xyz.com"
res = list(RECIPIENT.split(" "))

BODY_TEXT = email_message
client = boto3.client('ses',region_name=region)
# Create a multipart/mixed parent container.
msg = MIMEMultipart('mixed')
# Add subject,from and to lines.
msg['Subject'] = SES_subject
msg['From'] = SENDER
msg['To'] = res

msg_body = MIMEMultipart('alternative')
textpart = MIMEText(BODY_TEXT.encode(CHARSET),'plain',CHARSET)

# Add the text and HTML parts to the child container.
msg_body.attach(textpart)
msg.attach(msg_body)
if suite_Failed_data:
    att = MIMEApplication(open(ATTACHMENT,'rb').read())
    att.add_header('Content-disposition','attachment',filename=os.path.basename(ATTACHMENT))
    msg.attach(att)

try:
    # Provide the contents of the email.
    response = client.send_raw_email(
        Source=SENDER,Destinations=res,RawMessage={
            'Data': msg.as_string(),},)
# display an error if something goes wrong.
except ClientError as e:
    logger.exception(e)
else:
    logger.info("Email sent!")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。