0

1. pip error

I did

pip install smtplib

Then it says

Could not find a version that satisfies the requirement smtplib (from versions: ) No matching distribution found for smtplib

I confirmed that

pip install youtube_dl

works. So it's probably not a problem with pip.

2. Import error

Anyways, the code I am running is

import smtplib

GMAIL_USERNAME = "something"
GMAIL_PASSWORD = "something"
recipient = "something"
body_of_email = "body"
email_subject = "ha"

# The below code never changes, though obviously those variables need values.
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
session.login(GMAIL_USERNAME, GMAIL_PASSWORD)


headers = "\r\n".join(["from: " + GMAIL_USERNAME,
                       "subject: " + email_subject,
                       "to: " + recipient,
                       "mime-version: 1.0",
                       "content-type: text/html"])

# body_of_email can be plaintext or html!                    
content = headers + "\r\n\r\n" + body_of_email
session.sendmail(GMAIL_USERNAME, recipient, content)

But Anaconda prompt shows me error

ImportError: cannot import name 'SMTP'

Can't figure out why this weird thing is happening..

user3123767
  • 1,115
  • 3
  • 13
  • 22

0 Answers0