在使用腾讯企业邮箱发送邮件时出现报错:AttributeError: 'list' object has no attribute 'encode'

原因:收件人不能用列表存储数据,需要转为字符串,以逗号分割

解决方法:

将收件人列表转为字符串,以逗号分割

to_list = ['a@xx.com', 'b@xx.com']
msg['to'] = ','.join(to_list)

  

完整代码:

import smtplib
from email.mime.text import MIMEText
from email.header import Header name = 'xx@xxx.cn'
pwd = 'xxx'
to_list = ['xx@xxx.cn'] content = '<html><head><title>test</title></head><body>这是测试邮件内容</body></html>'
msg = MIMEText(content, 'html', 'utf-8')
msg['form'] = Header('huyang', 'utf-8')
msg['to'] = ','.join(to_list) # 重点是这个位置
msg['subject'] = Header('测试邮件', 'utf-8') #---发送
smtp = smtplib.SMTP_SSL('smtp.exmail.qq.com', 465)
smtp.login(name, pwd)
smtp.sendmail(name, to_list, msg.as_string())
print('发送成功!')

发送邮件时,报错:AttributeError: 'list' object has no attribute 'encode'的更多相关文章

  1. dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'

    有时候用到这个模块的时候会报错 AttributeError: 'CNAME' object has no attribute 'address' 如下所示 [root@ansible ch01]# ...

  2. py+selenium 明明定位不到元素,但却不报错或是报错AttributeError: 'list' object has no attribute 'click'【已解决】

    问题:定位不到元素,但却不报错或者出现报错AttributeError: 'list' object has no attribute 'click' 如图  或者  解决方法:   将”driver ...

  3. 关于flask登录视图报错AttributeError: '_AppCtxGlobals' object has no attribute 'user'

    在一个小程序中写了一个登录视图函数,代码如下: @app.route('/login',methods = ['GET','POST']) @oid.loginhandler def login(): ...

  4. Django2.2报错 AttributeError: 'str' object has no attribute 'decode'

    准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...

  5. python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'

    python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...

  6. 运行pytest,报错"AttributeError: 'module' object has no attribute 'xxx'"

    最近学习pytest被此问题困扰,敲脑壳,实在是不该.百度解决方法一大堆,我的问题怎么也解决不了,来看一下,我是怎么解决的,各位大佬勿喷,只是自己做笔记用,谢谢. 报错信息如下: 网上解决方法是这样的 ...

  7. 机器学习实战:KNN代码报错“AttributeError: 'dict' object has no attribute 'iteritems'”

    报错代码: sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 解决 ...

  8. python报错“AttributeError: 'set' object has no attribute 'items'“

    作为才开始学爬虫的萌新,遇到了一个这样的错,很懵逼 后面到网络到处查看大佬的解决方法,才发现headers的请求头部信息有错误,headers是一个字典,不是字符串,所以报错了 原代码 headers ...

  9. [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'

    原因:openpyxl版本低,需升级 pip install --upgrade openpyxl

  10. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

随机推荐

  1. 【Azure 事件中心】适用Mirror Maker生产数据发送到Azure Event Hub出现发送一段时间后Timeout Exception: Expiring 18 record(s) for xxxxxxx: 79823 ms has passed since last append

    问题描述 根据"将 Apache Kafka MirrorMaker 与事件中心配合使用"一文,成功配置了Mirror Maker来发送数据到Event Hub中.为什么只能成功运 ...

  2. Ubuntu20下安装NFS

    安装nfs-kernel-server apt install nfs-kernel-server 想好自己要把哪个目录作为NFS共享目录,创建目录 mkdir /mydata vim /etc/ex ...

  3. Linux系统查看主机性能

    查看主机的CPU性能: cat  /proc/cpuinfo cat /proc/meminfo |grep MemTotal    内存信息 查看物理cpu个数:cat /proc/cpuinfo ...

  4. MYSQL中正则表达式检索数据库

    1.MySQL中使用通配符检索数据库,之外还可以使用正则表达式来检索数据. 使用通配符   '_'  和   '%'的区别如下,   使用通配符的技巧:一般的来说 通配符可以处理数据,但是消耗内存较大 ...

  5. Ubuntu 与Windows 之间搭建共享文件夹

    工作中经常需要搭建Linux环境用于测试以及其他开发需求,办公电脑通常是Windows 系统,为便于让文件在两个系统之间传输,可以采取共享文件的方式实现: 1.安装samba 服务: sudo apt ...

  6. hesitation 单词学习 犹豫 hes 就是 her 粘 助记单词 here

    hesitation 单词学习 犹豫 hes 就是 her 粘 助记单词 here hes + itation(ite + ate + ion) hesitation 美: [ˌhezɪˈteɪʃ(ə ...

  7. Review Book for GEE(Graduate Entrance Examination)

    English is made up of phrases and idioms, in the case of both written and spoken usage. When learnin ...

  8. display标签交替显示不同行颜色

    问题 想要一个更加简单的支持列表数据分页和排序的方法. 解决方案 使用Display标签库和JSP标签库. 例4.13介绍了一个JSP页,它使用4.5节中的数据模型显示美国总统列表.这个JSP页面使用 ...

  9. Android IjkPlayer解决RTSP延时300ms左右

    简介 在上一篇<ijkplayer编译-RTSP>中介绍了,ijkplayer如何进行编译成so库的,以及如何开启rtsp.那么实际在使用的时候会发现延迟不是一般的大. 现在来介绍一下如何 ...

  10. 创建远程仓库&克隆项目(Github)

    创建远程仓库 在GitHub上注册一个账号,之后creat a new repository 创建的远程仓库把它看作一个百度网盘就可以了 克隆项目 1.远程仓库可以下载\克隆到本地 code :git ...