email = 'aashita9317@gmail.com'
send_email('Happy Hour Update',message,
from_addr=GMAIL_LOGIN, to_addr=email)
我收到错误AttributeError:'bytes'对象没有属性'encode'
def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = from_addr
msg['To'] = to_addr
msg['Reply-To'] = 'happyhours@noreply.com'
上面是它所引用的send_email函数,指向msg = MIMEText(message) 请帮忙
if _charset is None:
try:
_text.encode('us-ascii')
_charset = 'us-ascii'
except UnicodeEncodeError:
_charset = 'utf-8'
上面是 init (自身,_text,_subtype,_charset,policy)
中~~ anaconda3 \ lib \ email \ mime \ text.py中引用的anaconda3文件。答案 0 :(得分:1)
文档介绍了字符集编码的详细信息:https://docs.python.org/3/library/email.mime.html#email.mime.text.MIMEText
添加标题时,请使用msg.add_header('Subject', subject)
而不是msg['Subject'] = subject