Skip to content

Instantly share code, notes, and snippets.

@se7enack
Created February 19, 2024 19:06
Show Gist options
  • Save se7enack/45f2d04110b041b78cb102e651c6baeb to your computer and use it in GitHub Desktop.
Save se7enack/45f2d04110b041b78cb102e651c6baeb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from email.message import EmailMessage
import ssl
import smtplib
# create pw here https://myaccount.google.com/u/4/apppasswords after you enable 2-factor
password = "SOMEPASSWORD"
sender = "[email protected]"
def emailsend():
global subject
global receiver
global body
subject = "test"
receiver = "[email protected]"
body = '''
Hello World
'''
emailsend()
em = EmailMessage()
em['From'] = sender
em['To'] = receiver
em['Subject'] = subject
em.set_content(body)
context = ssl.create_default_context()
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(sender, password)
smtp.sendmail(sender, receiver, em.as_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment