问题描述
我的目标是向多个收件人发送电子邮件。当我只在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 (将#修改为@)