60

I'm trying to get the basic "hello world" of sendgrid working, but have so far been unsuccessful. The response returns code 202, suggesting that it will send the email, but the email never sends out. Does anyone know what's going on?

import sendgrid

sg = sendgrid.SendGridAPIClient(apikey='**my-api-key**')
data = {
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "subject": "Hello World from the SendGrid Python Library!"
    }
  ],
  "from": {
    "email": "[email protected]"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Hello, Email!"
    }
  ]
}
response = sg.client.mail.send.post(request_body=data)
print(response.status_code)
3
  • Did you check sendgrid api log? is should list the reason if it went through your code to them Commented Feb 13, 2017 at 21:44
  • 2
    Thanks, I didn't realize that was there. It was a receiving domain restriction (DMARC)?
    – Matrym
    Commented Feb 13, 2017 at 22:16
  • Did you finally solve it? if so, please share it, same situation here, thanks!
    – jmunozco
    Commented Apr 27, 2021 at 7:40

12 Answers 12

34

I just had this issue: I created an account with SendGrid and tried to get the basic example working, the API would return a 202 response, but the email was never sent, and the SendGrid web UI's activity feed showed no activity.

I submitted a SendGrid support ticket and ~8 hours later received a response saying that they had disabled my account's ability to send emails:

Hello,

Thanks for contacting SendGrid Support!

It looks like your account has been closed by our compliance team and this is the cause of the issue.

To reactivate we’d like to know a little more about the email you’ll be sending through SendGrid. Please elaborate on the following:

  1. The nature of your business, the services you provide, and your potential customer base

  2. Your sending frequency and volume

  3. How you collect your recipient addresses (link to opt in page, or sign up process)

  4. How you will allow your recipients to opt out of your emails (whether you plan to use SendGrid’s one-click unsubscribe feature, or if you have your own method)

  5. The types of messages you will be sending (transactional or marketing)

Please reply at your earliest convenience in order to continue the activation process. Thanks for your cooperation!


~15 hours after submitting my answers, I received a response saying my account had been "activated":

Hi nathan.wailes,

Thanks for the additional information! Your SendGrid account has been activated, and can now be used to send email. To get started, check out our Getting Started page.

If you hit any snags while you're getting set up, you can find solutions to common problems and FAQS in our Knowledge Base.

Let me know if you have any more questions!

Best,

Stevin O.

Associate Support Engineer


When I then ran the basic example code with my email address set up as the recipient, the email showed up immediately in my Gmail inbox.

3
  • 3
    This happened to me as well. Blocked by compliance. Commented Dec 5, 2017 at 1:04
  • 18
    Frustrating. This should be a 403. Commented Aug 19, 2021 at 1:21
  • I had the same problem - my account wad deactivated. Support ticket helped. Commented Jul 7, 2023 at 6:53
13

Debug this by going to the sendgrid api log here: https://app.sendgrid.com/email_activity

In my case, it was a DMARC receiving domain block.

2
8

The 202 Accepted Status Code returned from SendGrid does not really indicate that the message has been successfully delivered to the recipients inbox. It indicates that the message is valid and has been "Queued For Delivery". Now, it is up to the receiving server to deliver this message to the recipients inbox, or to send it to spam, or simply drop the message.

There are several reasons as to why messages that returns 202 Accepted Status code from SendGrid does not actually get delivered to the recipients inbox. For example:

  1. Invalid email address: The email address may no longer be valid (example, when an employee stops working at some company, their email might be removed from the company's system removing the ability to receive any email).
  2. Blocked Emails: If the sending IP or domain is blocked or if the recipients inbox provider has some filters set up such that some specific content of your email/campaign is considered spammy and thus gets automatically blocked.

Another thing to note is that SendGrid may send the messages to spam/junk if the domain authentication has not been properly set up. So make sure that your domain is properly authenticated.

Here is the link to the documentation from SendGrid that explains these event in details. https://sendgrid.com/blog/delivered-bounced-blocked-and-deferred-emails-what-does-it-all-mean/

5

In case someone will come across this looking for an answer to a similar problem. I solved the same problem by confirming the domain with DNS records - after that everything worked like charm.

In Sendgrind: Setting > Senders Authentication > Domain Authentication

1
  • This also worked for me sending from my .com.au domain, which uses gmail as the mail server. Commented Oct 30, 2019 at 12:09
5

I had same issue and solved it by adding new api key with full access

4

For us, the problem was that the used dynamic template was not yet set to "active". Unfortunately no error was shown about the in the API response or the log.

Activating the email template solved this and emails are no longer dropped.

1
  • same for me. Pretty weird that you have to activate all of them before using Commented Mar 13, 2023 at 9:49
2

The same issue occurred when DNS is not verified and you are not using register email in from email. Just change from email to register email.

0

I recently got the same issue. My e-mails were not sent without any reason, the response status was 202, e-mail activity was empty. The possible solution is to add a company details and add an unsubscribe block to e-mail. That worked for me.

I'm implementing a password reset feature and it's a little weird to have an unsubscribe block for this. I'll try to figure out what was the real reason of such silent suppression. Probably it's because I tried to send a draft debug e-mail several times which was looked like a spam. Maybe SendGrid has some smart algorithms for detecting this.

0

I also had this issue. I contacted sendgrid support however while waiting I changed the dummy data to real data I was calling sendgrid API with and then it started working.

in particular I changed the from email address to show my own domain.

0

In my case the 302 was a result of incomplete form fields. I had a "message" field that was sometimes empty. By using string interpolation I was able to ensure that the field was always submitted with something and not a null value. Thereafter my form submissions worked.

It's super frustrating that the error code is still, after 6 years, inappropriate and not documented anywhere by SendGrid.

0

202 means the message is now taken into consideration by SendGrid's servers for further processing. Any outcome can be expected from there on.

To get actual delivery or bounce statuses you must either check in the UI client portal under "Activity" or subscribe to an event webhook: https://docs.sendgrid.com/for-developers/tracking-events/event

-2

For me the template was the issue. When using the template engine make sure to use {{variable}} instead of {{ variable }}. Afterwards I received the emails as usual.

Not the answer you're looking for? Browse other questions tagged or ask your own question.