Skip to content

Instantly share code, notes, and snippets.

@kovalbogdan95
Created February 21, 2020 20:45
Show Gist options
  • Save kovalbogdan95/a01d5292019aba3177a9552aec494c7b to your computer and use it in GitHub Desktop.
Save kovalbogdan95/a01d5292019aba3177a9552aec494c7b to your computer and use it in GitHub Desktop.
Send email via Gmail smtp
import smtplib, ssl
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = "my@gmail.com"
receiver_email = "your@gmail.com"
password = input("Type your password and press enter:")
message = """\
Subject: Hi there
This message is sent from Python."""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment