Created
April 28, 2024 03:38
-
-
Save ensean/07d1b23a5623a46e09042830773f33a8 to your computer and use it in GitHub Desktop.
python-smtp-gmail-from-ec2.py
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 = 465 # For SSL | |
smtp_server = "smtp.gmail.com" | |
sender_email = "[email protected]" # Enter your address | |
receiver_email = "[email protected]" # Enter receiver address | |
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_SSL(smtp_server, port, context=context) as server: | |
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
gmail 通过 smtp 发送邮件需要创建 app 密码 https://myaccount.google.com/apppasswords