Skip to content

Instantly share code, notes, and snippets.

@ensean
Created April 28, 2024 03:38
Show Gist options
  • Save ensean/07d1b23a5623a46e09042830773f33a8 to your computer and use it in GitHub Desktop.
Save ensean/07d1b23a5623a46e09042830773f33a8 to your computer and use it in GitHub Desktop.
python-smtp-gmail-from-ec2.py
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)
@ensean
Copy link
Author

ensean commented Apr 28, 2024

gmail 通过 smtp 发送邮件需要创建 app 密码 https://myaccount.google.com/apppasswords

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment