An error occurred when sending emails using Tencent Enterprise Mailbox: AttributeError:’list’ object has no attribute’encode’
Reason: The recipient cannot store data in a list, it needs to be converted to a string, separated by commas
Solution:
Convert the recipient list into a string, separated by commas
msg[
'to'
]
=
','
.join(to_list)
Complete code:
import smtplib from email.mime.text import MIMEText from email.header import Header name = ' [email protected] ' pwd = ' xxx ' to_list = [ ' [email protected] ' ] content = ' <html><head><title>test</title></head><body>This is the test email content</body></html> ' msg = MIMEText(content, ' html ' , ' utf -8 ' ) msg[ ' form ' ] = Header( ' huyang ' , ' utf-8 ' ) msg[ ' to ' ] = ' , ' .join(to_list) # The focus is on this position msg[ ' subject ' ] = Header( ' Test mail ' , ' utf-8 ' ) # ---Send smtp = smtplib.SMTP_SSL( ' smtp.exmail.qq.com ' , 465 ) smtp.login(name, pwd) smtp.sendmail(name, to_list, msg.as_string()) print ( ' Send successfully! ' )
Read More:
- How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘
- [Solved] Selenium python send_key error: list object has no attribute
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- AttributeError: DatetimeProperties object has no attribute
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- [Solved] Paramiko error: AttributeError: ‘NoneType’ object has no attribute ‘time’
- [Solved] Python Selenium Error: AttributeError: ‘WebDriver‘ object has no attribute ‘find_element_by_xpath‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘HTMLWriter‘ object has no attribute ‘_temp_names‘
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- [Solved] Networkx Error: Attributeerror: ‘graph’ object has no attribute ‘node’
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError WriteOnlyWorksheet object has no attribute cell
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- Python Openyxl Error: AttributeError: ‘int‘ object has no attribute ‘upper‘ [How to Solve]
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] Python Keras Error: AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘