Error When Using smtplib in Python Backend App

I’m testing a script that sends an email from a backend app.

When the app invokes, it returns the following error message: Error: [Errno -2] Name or service not known!

I’m executing the following script:

from corva import Api, Cache, Logger, StreamTimeEvent, stream
import json
import smtplib


@stream
def lambda_handler(event: StreamTimeEvent, api: Api, cache: Cache):
    send_email()
    return {
        'statusCode': 400,
        'body': json.dumps('This is an error notification')
    }

# =============================================================================
# SEND EMAIL FUNCTION
# =============================================================================
def send_email():
    gmail_user = 'my_email'
    gmail_app_password = "my_password"
    sent_from = gmail_user
    sent_to = ['michael.cortez@corva.ai']
    sent_subject = "Error Notification"
    sent_body = "I'm an Error"

    email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(sent_to), sent_subject, sent_body)

    try:
        server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
        server.ehlo()
        server.login(gmail_user, gmail_app_password)
        server.sendmail(sent_from, sent_to, email_text.encode("utf-8"))
        server.close()
        Logger.info(email_text)
        Logger.info('Email sent!')
    except Exception as exception:
        Logger.info("Error: %s!\n\n" % exception)
# =============================================================================
# END OF SEND EMAIL FUNCTION
# =============================================================================
send_email()```