Created
February 19, 2024 19:06
-
-
Save se7enack/45f2d04110b041b78cb102e651c6baeb to your computer and use it in GitHub Desktop.
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
#!/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