Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPError: HTTP Error 401: Unauthorized for sendgrid integration with python

def sendEmail(to,apNumber,paperType,zipedFile):

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get("API-KEY"))

    to_email = mail.Email( "[email protected]")
    from_email = mail.Email( "[email protected]" )
    subject = 'This is a test email'
    content = mail.Content('text/plain', 'Example message.')
    message = mail.Mail(from_email, subject, to_email, content)
    response = sg.client.mail.send.post(request_body = message.get())
    return response
like image 766
vinay Avatar asked Sep 27 '16 06:09

vinay


1 Answers

Setup Environment Variables.

To Set up environment Variable follow the below 3 steps

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
like image 193
Shridhar Patil Avatar answered Oct 07 '22 01:10

Shridhar Patil