<jupyter_start><jupyter_text>You must first ensure your myaccount setting has "'Allow less secure apps" turned on for the script below to work.<jupyter_code>import smtplib
from email.mime.text import MIMEText
from email.utils import COMMASPACE
from getpass import getpass
GMAIL_USER = input("Enter gmail email: ")
GMAIL_PWD = getpass("Enter password: ")
SUBJECT = 'Email from myself'
BODY = 'You ready for some donuts?'
TO = '<EMAIL>'

def sendEmail(sender, pwd, to, subject, message):
    recipient = to if type(to) is list else [to]
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = COMMASPACE.join(recipient)
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo()
    server.starttls()

    try:
        server.login(sender,pwd)
        print('Successfully authenticated...')
    except smtplib.SMTPAuthenticationError:               # Check for authentication error
        return " Authentication ERROR"

    try:
        server.sendmail(sender,recipient,msg.as_string())
        print('Email sent!')
    except smtplib.SMTPRecipientsRefused:                # Check if recipient's email was accepted by the server
        return "ERROR"
    server.quit()
sendEmail(GMAIL_USER, GMAIL_PWD, TO, SUBJECT, BODY)<jupyter_output>Successfully authenticated...
Email sent!
{'fraction_non_alphanumeric': 0.10324039186134137, 'fraction_numerical': 0.002260738507912585, 'mean_word_length': 3.6271777003484322, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '306320', 'license': 'MIT', 'n_tokens_mistral': 418, 'n_tokens_neox': 415, 'n_words': 117, 'path': 'jupyter_notebooks/email/sending_email_with_gmail.ipynb', 'repo_name': 'manual123/Nacho-Jupyter-Notebooks', 'size': '1342'}