我已经编写了一段非常简单的代码,可以将简单的字符串发送到我的gmail,并且在使用小字符串时可以完美地工作; 当我开始使用更大的字符串时,我收到了一堆加密的文本,而不是普通的字符串。
有人遇到这种问题吗?它与安全性有关并且有可能避免吗?
def send_email(sender_email,receiver_email,password,txt, subject) :
message = MIMEMultipart(txt)
message["Subject"] = subject
message["From"] = sender_email
message["To"] = receiver_email
# Turn these into plain/html MIMEText objects
part1 = MIMEText(txt, "plain")
message.attach(part1)
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, txt)
这就是我收到的:
TsK6IEFsYXJtZTogKDcyCk1lbnNhZ2VtOiAgJ0FWSVNPIC0gU0VSVk8nClRpcG8gZGUgRXJybzog
ICdFJwpTdGF0dXMgcGFyYWRvOiAgJ0gnClByb2NlZGltZW50byBkZSBlbGltaW5hw6fDo286ICAn
TycKRXhpYmnDp8Ojb286ICAnQXp1bCcKQ2F1c2E6ICAnTyBzZXJ2byBtb3RvciBlc3TDoSBjYXJy
ZWdhZG8gZGUgZm9ybWEgYW5vcm1hbC4nCkHDp8OjbzogICdEZXNsaWd1ZSBvIE5DIGUgYSBtw6Fx
dWluYQo=
答案 0 :(得分:0)
像Torxed说 “您可能想使用MIMEText,并且2:server.sendmail(sender_email,receiver_email,txt)应该是server.sendmail(sender_email,receiver_email,消息)”
这个和 server.sendmail(sender_email,receiver_email,message.as_string)
“ message.as_string”
显然解决了这个问题! 谢谢