<filename>blog/util.py
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from django.conf import settings
import requests


def verify_hcaptcha(secret, h_captcha_response):
    if settings.DEBUG:
        return True
    res_body = requests.post('https://hcaptcha.com/siteverify', data={
        'secret': secret,
        'response': h_captcha_response
    }).json()
    return 'success' in res_body


def send_mail(from_email, to_email, subject, html_content):
    try:
        SendGridAPIClient(settings.SITE_SETTINGS['SENDGRID']).send(Mail(
            from_email=from_email,
            to_emails=to_email,
            subject=subject,
            html_content=html_content,
            
        ))
        return True
    except Exception as e:
        print(e.message)
        return False

<filename>blog/util.py
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from django.conf import settings
import requests


def verify_hcaptcha(secret, h_captcha_response):
    if settings.DEBUG:
        return True
    res_body = requests.post('https://hcaptcha.com/siteverify', data={
        'secret': secret,
        'response': h_captcha_response
    }).json()
    return 'success' in res_body


def send_mail(from_email, to_email, subject, html_content):
    try:
        SendGridAPIClient(settings.SITE_SETTINGS['SENDGRID']).send(Mail(
            from_email=from_email,
            to_emails=to_email,
            subject=subject,
            html_content=html_content,
            
        ))
        return True
    except Exception as e:
        print(e.message)
        return False
