Envío de gmail usando fallas de python
1. error de pip
yo hice
pip install smtplib
Entonces dice
Could not find a version that satisfies the requirement smtplib (from versions: ) No matching distribution found for smtplib
Yo confirme que
pip install youtube_dl
trabajos. Entonces probablemente no sea un problema con pip.
2. Error de importación
De todos modos, el código que estoy ejecutando es
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)
Pero el aviso de Anaconda me muestra un error
ImportError: cannot import name 'SMTP'
No puedo entender por qué está sucediendo esta cosa extraña ...