Flask-User icon indicating copy to clipboard operation
Flask-User copied to clipboard

SendGrid email adapter does not work

Open bmarsh9 opened this issue 5 years ago • 1 comments

When sending emails with SendGrid, the code does not work. For example, in the file sendgrid_email_adapter.py, the code self.sg = SendGridAPIClient(apikey=sendgrid_api_key) is invalid with the sendgrid library.

I was able to successfully send email by replacing the function with the following code:

def send_email_message(self, recipient, subject, html_message, text_message, sender_email, sender_name):
        if not current_app.testing:  # pragma: no cover
            try:
                # Prepare Sendgrid helper objects
                from sendgrid.helpers.mail import Mail
                msg = Mail(
                  from_email=sender_email,
                  to_emails=recipient,
                  subject=subject,
                  html_content=html_message)
                response = self.sg.send(msg)
                print(response.status_code)
                print(response.body)
                print(response.headers)
            except ImportError:
                raise ConfigError(SENDGRID_IMPORT_ERROR_MESSAGE)
            except Exception as e:
                print(e)
                #print(e.body)
                raise

bmarsh9 avatar Jan 12 '20 21:01 bmarsh9

And change self.sg = SendGridAPIClient(apikey=sendgrid_api_key) to self.sg = SendGridAPIClient(sendgrid_api_key)

bmarsh9 avatar Jan 12 '20 21:01 bmarsh9