Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting HTTP 400 Bad request but email is getting delivered from sendgrid. #866

Closed
r-puri opened this issue Jan 23, 2020 · 0 comments
Closed

Comments

@r-puri
Copy link

r-puri commented Jan 23, 2020

Issue Summary

I am getting a HTTP 400 Bad request response when calling sendgrid email, BUT THE EMAIL IS GETTING SENT OUT. I expect if error is getting returned then the email should not be delivered.

Steps to Reproduce

  1. run snippet below.

Code Snippet

sg = sendgrid.SendGridAPIClient(settings.SENDGRID_API_KEY)
template_data = Content("text/html", template)
to_email = Email(to_email)
mail = Mail(from_email, subject, to_email, template_data)
response = sg.client.mail.send.post(request_body=mail.get())

Here is the output of mail.get()

   "from":{ 
      "email":"[email protected]"
   },
   "subject":"Employees trainings are due on 2020-01-24",
   "personalizations":[ 
      { 
         "to":[ 
            { 
               "email":""
            }
         ]
      }
   ],
   "content":[ 
      { 
         "type":"text/html",
         "value":"<!DOCTYPE html\n  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n\n\n  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n  <meta name="viewport" content="width=device-width, initial-scale=1">\n  <title>SecurityAdvisor</title>\n  <style type="text/css">\n    table,\n    td {\n      mso-table-lspace: 0;\n      mso-table-rspace: 0 !important\n    }\n\n    span.preheader {\n      display: none !important;\n    }\n\n    @media only screen and (max-width: 768px) {\n      table[class=contentTableOuter] {\n        width: 95%\n      }\n\n      table[class=contentTableInner] {\n        width: 95%;\n        margin: 0 auto\n      }\n\n      table[class=fLeft],\n      table[class=fRight] {\n        width: 100%;\n        margin-bottom: 10px;\n        border: none\n      }\n\n      table[class=fLeft] td,\n      table[class=fRight] td {\n        height: auto;\n        border: none;\n        text-align: center\n      }\n\n      img[class=resImg] {\n        width: 100% !important;\n        height: auto !important\n      }\n\n      .d-none {\n        display: none\n      }\n    }\n\n  </style>\n\n\n\n<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ececec">\n  \n    <td align="center" valign="top" bgcolor="#ececec" height="20"> \n  \n  \n    <td align="center" valign="top" bgcolor="#ececec">\n\n      <table width="700" border="0" align="center" cellpadding="10" cellspacing="0" class="contentTableOuter">\n        \n          <td align="center" valign="top" bgcolor="#FFFFFF">\n            <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" class="contentTableInner">\n              \n                <td align="left" valign="top">\n                  <table width="100%" border="0" align="left" cellpadding="20" cellspacing="0" class="fLeft">\n                    \n                      <td align="center" valign="middle">\n                        <a href="https://www.securityadvisor.io/" target="_blank">\n                          <img src="https://logouploadtest.s3.amazonaws.com/OrganisationLogo/305cd33aa1cc49ba945eb86844e1683c" alt="" width="300" border="0" />\n                    \n                  \n                \n              \n              \n                <td align="left" valign="top">\n                  <hr width="100%" size="1" noshade="noshade" style="border:1px solid #f1f1f2">\n                \n              \n              \n                <td height="20" align="left" valign="top"> \n              \n              <tr contenteditable="true">\n                <td style="padding: 15px;">\n                  <p style="font-size: 15px;">Hello Manager


\n                  

This is a reminder. The following trainings are due to be completed by the users by January 24, 2020

\n                  
    \n                    \n                      
  • \n                        

    California Consumer Privacy Act : <a href="https://localhost:8001/gw/c2c7f4bd55754f068fff5a13f4d1d243/"> Click here to start  

    \n                      
  • \n                    \n                  
\n                  
\n                  

 Users List

\n                  
    \n                    \n                      
  • \n                        

    Yahoo Yahoo last name - [email protected]

    \n                      
  • \n                    \n                      
  • \n                        

    [email protected] - [email protected]

    \n                      
  • \n                    \n                  
\n\n                  

Regards,

\n                  

Your Information Security Team

\n                  

\n                \n              \n            \n          \n        \n\n        \n          <td align="right" valign="top" bgcolor="#666666"\n              style="font-size: 13px; font-family:Arial, Helvetica, sans-serif; color:#ffffff">\n\n            Powered by SecurityAdvisor\n            <a href="https://www.securityadvisor.io" target="_blank" style="color:#fff; text-decoration: none">\n              <img src="https://content.securityadvisor.io/static/assets/images/securityadvisor-logo-footer.png"\n                   align="center" width="120" alt="SecurityAdvisor" border="0" class="" style="padding-left:10px" />\n          \n        \n\n        \n          <td align="center" valign="top" bgcolor="#ececec"\n              style="font-size: 12px; font-family:Arial, Helvetica, sans-serif; color:#666">\n            You received this email because your organization is registered with SecurityAdvisor. Please contact your\n            administrator to unsubscribe.\n            
 
\n            We respect your privacy. View our <a href="https://www.securityadvisor.io/sabweb/privacy" target="_blank"\n                                                 style="color:#666">Privacy Policy.\n          \n        \n\n      \n    \n  \n\n  \n    <td align="center" valign="top" bgcolor="#ececec" height="20"> \n  \n\n\n\n\n"
      }
   ]
}

Exception/Log

HTTP Error 400: Bad Request

Technical details:

  • sendgrid-python version:5.6.0
  • python version:3.7.4
@r-puri r-puri closed this as completed Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant