• Fail: send_email("admin@checkio.org","Alex")

Question related to mission Welcome Email by SendGrid

 

Hi, Can you help me to find the problem in this code?

import sendgrid
from sendgrid.helpers.mail import Email,  Mail, Content

API_KEY = "xxxxxxxxxx"
SUBJECT = "Welcome"
BODY = "Hi {name}"

sg = sendgrid.SendGridAPIClient(API_KEY)

def send_email(email, name):
    global API_KEY
    global SUBJECT
    global BODY

    BODY="Hi {}".format(name)

    message = Mail(
    from_email='xxx@gmail.com',
    to_emails=email,
    subject=SUBJECT,
    html_content=BODY
    )

    message.content = Content('text/plain', BODY)
    try:
        sg = sendgrid.SendGridAPIClient(API_KEY)
        response = sg.send(message)
        print(response.status_code)
        print(response.body)
        print(response.headers)

    except Exception as e:
        print(e)