是否可以将消息转换为unicode?因为它给出了错误
_fix_eols(msg).encode('ascii')UnicodeEncodeError:'ascii'编解码器无法对位置105-107中的字符进行编码:序数不在范围(128)中
fromaddrs = tkinter.StringVar()
password = tkinter.StringVar()
toaddrs = tkinter.StringVar()
subject = tkinter.StringVar()
message = tkinter.StringVar()
entry_from_address = ttk.Entry(window, textvariable=fromaddrs)
entry_from_password = ttk.Entry(window, textvariable=password)
entry_to_address = ttk.Entry(window, textvariable=toaddrs)
entry_subject = ttk.Entry(window, textvariable=subject)
entry_message = ttk.Entry(window, textvariable=message)
def email_send(*args):
mail_details= """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (fromaddrs.get(), ", ".join(toaddrs.get()), subject.get(), message.get())
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddrs.get(), password.get())
server.sendmail(fromaddrs.get(), toaddrs.get(), mail_details)
server.quit()
print("message send")
答案 0 :(得分:1)
作为解决方法,请尝试
server.sendmail(fromaddrs.get(), toaddrs.get(), mail_details.encode("utf-8"))