Last active
April 4, 2022 09:52
-
-
Save darideveloper/fcff9b3be2b8fc033392b966f4810623 to your computer and use it in GitHub Desktop.
Enviar correos de texto plano con python. Script del curso Python Emails, Dari Developer: https://www.youtube.com/channel/UCXWTlKzN_udf9LGqlDsuByg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
# Información de tu correo | |
email = "[email protected]" | |
password = "gmbkfyojzhwxxxxx" | |
smtp_server = "smtp.gmail.com" | |
smtp_port = "587" | |
# Conectarse con el servicio de correo | |
smtpObj = smtplib.SMTP (smtp_server, smtp_port) | |
smtpObj.ehlo () | |
smtpObj.starttls () | |
# Iniciar sesión con tu usuario y contraseña | |
smtpObj.login (email, password) | |
# Diccionario de usuarios (de correos a enviar) | |
to_emails = { | |
"[email protected]": "Juan", | |
"[email protected]": "Maria", | |
"[email protected]": "Pedro" | |
} | |
# Ciclo por cada correo y nombre | |
for to_email, name in to_emails.items(): | |
# Envíar correo personalizado a cada email | |
smtpObj.sendmail (email, | |
to_email, | |
f"Subject: Hola {name} \n\n Este es un correo de ejemplo") | |
# Mostrar mensaje de cuál correo fue enviado | |
print (f"enviado correo a: {to_email}...") | |
# Cerrar conexión con el servicio de correo | |
smtpObj.quit () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment