Home > OS >  sendgrid-python client works with one email, but not another
sendgrid-python client works with one email, but not another

Time:03-03

I've got Twilio SendGrid's Python API client working and sending emails with one from_email address. In a new/different application, I want to use the same SendGrid account, but use a different from_email. I've tried just changing the from_email field in the Mail class, but that doesn't work; I get the following error:

Traceback (most recent call last):
  ...
  File "C:\Users\my\path\envs\myproject\lib\site-packages\sendgrid\base_interface.py", line 62, in send
    return self.client.mail.send.post(request_body=message)
  File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 277, in http_request
    self._make_request(opener, request, timeout=timeout)
  File "C:\Users\my\path\envs\myproject\lib\site-packages\python_http_client\client.py", line 184, in _make_request
    raise exc
python_http_client.exceptions.ForbiddenError: HTTP Error 403: Forbidden

I've confirmed that all of my code works with the old from_email; the only difference is that the new from_email I'm trying to use.

Also, both email addresses I'm using are gmail-based emails; One is a @gmail.com email and the other is a custom business domain, but the email is run on gmail. The custom business domain email address is the email address that is currently working.

Is there a setting in my SendGrid account I need to change? Or do I need to create an new API key for this new from_email?

CodePudding user response:

Twilio SendGrid developer evangelist here.

In order to send an email from your gmail account you will need to verify that email as a sender before you can send from it.

Email verification is a method for SendGrid to understand that you own the email. However, domain authentication, which I assume you have set up with your domain, is much better for deliverability. Even when SendGrid knows that you own the @gmail.com account, Google also knows that when you send an email from that address via SendGrid that they didn't send it, so you risk falling into spam inboxes. However, in order to make your API request succeed, you need to verify the email.

  • Related