Фон
Я использую ма c. Я выполнил инструкции SendGrids о том, как настроить его в Django:
Шаг 1)
echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
Шаг 2)
pip install sendgrid
Шаг 3) Создайте файл send-email.py, содержащий следующее:
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='from_email@example.com',
to_emails='to@example.com',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e.message)
Шаг 4)
python send-email.py
Проблема
Однако мой терминал выводит HTTP Error 403: Forbidden
с шагом 4, и электронная почта не отправляется. Кто-нибудь может мне с этим помочь?