Skip to content

Instantly share code, notes, and snippets.

@darideveloper
Created January 30, 2021 11:56
Show Gist options
  • Select an option

  • Save darideveloper/23a888bbbdb976dc8efc9babc19b1e07 to your computer and use it in GitHub Desktop.

Select an option

Save darideveloper/23a888bbbdb976dc8efc9babc19b1e07 to your computer and use it in GitHub Desktop.
Enviar correos desde python
#! 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 = {
"darialternative@yahoo.com": "Juan",
"darialternative@outlook.com": "Maria",
"darialternative@aol.com": "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 ("your_email@gmail.com", "your_password")
# Loop for each email in list
for email, name in to_emails.items():
# Send email
smtpObj.sendmail('darialternative@gmail.com',
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