55

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": "me@gmail.com"
        }
      ],
      "subject": "Hello World from the SendGrid Python Library!"
    }
  ],
  "from": {
    "email": "me@gmail.com"
  },
  "content": [
    {
      "type": "text/plain",
      "value": "Hello, Email!"
    }
  ]
}
response = sg.client.mail.send.post(request_body=data)
print(response.status_code)
Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95
Matrym
  • 16,643
  • 33
  • 95
  • 140

10 Answers10

31

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.

Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95
12

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.

Matrym
  • 16,643
  • 33
  • 95
  • 140
  • 4
    What if the activity feed displays nothing? I'm following the example at https://sendgrid.com/docs/Integrate/Code_Examples/v3_Mail/nodejs.html to the t, there are no errors, getting status code 202, and there's still nothing in the link included in this answer. – Adam Freymiller Mar 03 '17 at 20:31
  • 1
    Same problem, however the api log shows nothing in my case as well. – Liquidgenius Jun 27 '19 at 17:47
7

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/

STZ
  • 161
  • 2
  • 10
5

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

Dev vora
  • 101
  • 1
  • 3
4

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

dsjacobsen
  • 121
  • 5
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

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.

Swapnil
  • 91
  • 3
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.

alexey_detr
  • 1,640
  • 1
  • 17
  • 15
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

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.

mika
  • 86
  • 8