Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Created September 23, 2015 02:22
Show Gist options
  • Select an option

  • Save tklee1975/06571058ef76105ad2e2 to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/06571058ef76105ad2e2 to your computer and use it in GitHub Desktop.
Python: Send email by SMTP
#!/usr/bin/python
import smtplib
gmail_user = "sender@gmail.com"
gmail_pwd = "sender_password"
def send_email(msg, gmail_user, gmail_pwd, to_list):
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to_list, msg)
mailServer.quit()
def main():
send_email("Hello everybody", gmail_user, gmail_pwd, ["receiver@gmail.com"])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment