Created
January 30, 2021 11:56
-
-
Save darideveloper/23a888bbbdb976dc8efc9babc19b1e07 to your computer and use it in GitHub Desktop.
Enviar correos desde python
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
#! python3 | |
""" | |
Code for my youtube course: Python emails. | |
Youtube chanel (in spanish): https://www.youtube.com/channel/UCXWTlKzN_udf9LGqlDsuByg | |
""" | |
import smtplib | |
# List of recipents | |
to_emails = { | |
"[email protected]": "Juan", | |
"[email protected]": "Maria", | |
"[email protected]": "Alberto" | |
} | |
# Connect to server and port | |
smtpObj = smtplib.SMTP ('smtp.gmail.com', 587) | |
# Send hello to smtp | |
smtpObj.ehlo() | |
# Active encriptation | |
smtpObj.starttls() | |
# login | |
smtpObj.login ("[email protected]", "your_password") | |
# Loop for each email in list | |
for email, name in to_emails.items(): | |
# Send email | |
smtpObj.sendmail('[email protected]', | |
email, | |
'Subject: Email example\n\nGood morning {} This is an example email'.format(name)) | |
# Confirmation message | |
print ("Correo enviado a {}".format (name)) | |
# Close connection | |
smtpObj.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment