List 通过Amazon SES向多人发送电子邮件时出现AttributeError
我的目标是向多个收件人发送电子邮件。当我在RECIPIENT变量中只发送一封电子邮件并提供Destinations=[RECIPIENT]时,代码会运行,但当我发送多封带有以下代码的电子邮件时,代码会出错List 通过Amazon SES向多人发送电子邮件时出现AttributeError,list,encode,amazon-ses,attributeerror,List,Encode,Amazon Ses,Attributeerror,我的目标是向多个收件人发送电子邮件。当我在RECIPIENT变量中只发送一封电子邮件并提供Destinations=[RECIPIENT]时,代码会运行,但当我发送多封带有以下代码的电子邮件时,代码会出错 “AttributeError:'列表'对象没有'encode'属性” 任何指点都很感激 RECIPIENT = "abc@xyz.com efg@xyz.com" res = list(RECIPIENT.split(" ")) BODY_TEXT
“AttributeError:'列表'对象没有'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!")