Skip to content

Instantly share code, notes, and snippets.

@jcarlosroldan
Last active July 24, 2018 11:56
Show Gist options
  • Save jcarlosroldan/e596c0f896f5f7d78456a98b3ecbaab9 to your computer and use it in GitHub Desktop.
Save jcarlosroldan/e596c0f896f5f7d78456a98b3ecbaab9 to your computer and use it in GitHub Desktop.
Send a mail using SMTP
from smtplib import SMTP
def send_gmail(to, subject, text, username="********@gmail.com", password="********"):
""" Send a mail using simple SMTP. """
server = SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username, password)
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s"%(username, to, subject, text)
server.sendmail(username, to, msg)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment