我遇到了一个功能问题,假设连接到谷歌邮件并发送电子邮件。
该功能如下所示:
def emailSend(fileInput):
to = ["blah@blah.com","blah2@blah.com","blah3@blah.com"]
toUpdate = to[emailVem]
gmail_user = "lala@gmail.com"
gmail_pwd = "password"
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + toUpdate + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:ERROR \n'
print (header)
msg = header + "\nError, kördes senast: \n\n" + fileInput
smtpserver.sendmail(gmail_user, toUpdate, msg)
print (msg)
print ('done!')
smtpserver.close()
需要[emailVem],因为我只想发送一封电子邮件。它会给我一个介于0-3之间的数字。我得到的错误是:
Traceback (most recent call last):
File "C:\Users\Tim\Documents\ErrorArtPython\Test\errorTimeTest.py", line 56, in <module>
emailSend(time.ctime(os.path.getmtime("F:\\Export\\art_data.txt")))
File "C:\Users\Tim\Documents\ErrorArtPython\Test\errorTimeTest.py", line 33, in emailSend
smtpserver.sendmail(gmail_user, toUpdate, msg)
File "C:\Python34\lib\smtplib.py", line 764, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 10: ordinal not in range(128)
非常感谢我能得到的任何帮助!