I am new to python. I am trying to send mails using the following Python code and I am using a code editor Jupyter. I have enabled IMAP in my gmail account and have turned on the access for less secured app. The code editor i am using is unable to compile the line
server = smtplib.SMTP('smtp.gmail.com', 587)
Can someone please tell me what I am doing wrong?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
fromaddr = 'abc@gmail.com'
toaddr = 'abc@gmail.com'
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = 'SUBJECT OF THE MAIL'
body = 'YOUR MESSAGE HERE'
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(fromaddr, 'YOUR PASSWORD')
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()