Skip to content

Days 65-68 Heroku - Sendgrid changes #36

Closed
@shutteritch

Description

@shutteritch

Hello!

I had two errors when trying to send email with sendgrid.

The first seemed to relate to the order of the variables in which I had to change from:
mail = Mail(from_email, subject, to_email, content)
to:
mail = Mail(from_email, to_email, subject, content)

And then the second referred to the response which I had to change from:
response = sg.client.mail.send.post(request_body=mail.get())
to:
response = sg.send(mail)

I also discovered that I didn't need to import Email & Content so the following worked for me:

import sendgrid
from sendgrid.helpers.mail import Mail

sg = sendgrid.SendGridAPIClient(api_key="MY_API_KEY")

from_email = "test@example.com"
subject = "Winter is coming"
to_email = "myemail@gmail.com"
content = "Hey Iain, This works much better"

mail = Mail(from_email, to_email, subject, content)

response = sg.send(mail)

print(response.status_code)
print(response.body)
print(response.headers)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions