Created
February 21, 2020 20:45
-
-
Save kovalbogdan95/a01d5292019aba3177a9552aec494c7b to your computer and use it in GitHub Desktop.
Send email via Gmail smtp
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
import smtplib, ssl | |
port = 587 # For starttls | |
smtp_server = "smtp.gmail.com" | |
sender_email = "[email protected]" | |
receiver_email = "[email protected]" | |
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