Jama Mohamed
Jama Mohamed

Reputation: 3405

Sendgrid not sending email

I am using flask python to send emails using sendgrid, i followed the doc, where i install pip install sendgrid and did the following, but the email is not sent and responds with a status code of 202, is there something i am missing

import sendgrid
from sendgrid.helpers.mail import Email, Content, Mail

def sendEmail():
        try:
            sg = sendgrid.SendGridAPIClient(apikey="hiddedAPIKey")
            from_email = Email("[email protected]")
            to_email = Email("[email protected]")
            subject = "Sending with SendGrid is Fun"
            content = Content("text/plain", "and easy to do anywhere, even with Python")
            mail = Mail(from_email, subject, to_email, content)
            response = sg.client.mail.send.post(request_body=mail.get())
            print(response.status_code)
            print(response.body)
        except:
            print("the was an error")

Upvotes: 0

Views: 1105

Answers (1)

skaul05
skaul05

Reputation: 2334

Your emails must be going to spam. There are two ways to tackle this situation

  • You can go into the spam folder and click on the from email address as the trusted email address. (Won't help for multiple sender addresses)
  • Check the sendgrid official documentation to avoid emails to land into spam.

Upvotes: 1

Related Questions