from smtpd import SMTPServer
import smtplib, ssl
def sendEmail(message):
smtp_server = "smtp.gmail.com"
port = 465
sender_email = "[email protected]"
password = "password"
receiver_email = "[email protected]"
context = ssl.create_default_context()
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo()
server.starttls(context=context)
server.ehlo()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
except Exception as e:
print(e)
finally:
server.quit()
got this error while running the code
name 'smtp_server' is not defined
Traceback (most recent call last):
File "/Users/dhruvsahgal/Desktop/dhruv_practice/project1/send_email.py", line 24, in <module>
server.quit()
NameError: name 'server' is not defined
Please help me find out what the error is I am running this on mac os in vs code