prof-rossetti / intro-to-python

An Introduction to Programming in Python
Other
97 stars 246 forks source link

Sendgrid API Issues #41

Closed s2t2 closed 1 year ago

s2t2 commented 4 years ago

Students are having various issues with getting a working Sendgrid API Key. Posting possible solutions here.

s2t2 commented 4 years ago

From a student:

For those having "email forbidden" issues, are you using the same email that you used for your sendgrid account? I was having a similar issue for another project and that solved it

s2t2 commented 4 years ago

Some see "your account is temporarily under review"s under-review

s2t2 commented 4 years ago

Another student shared the email message from sendgrid that provides additional instructions:

Screenshot 2020-06-18 17 39 20

We can probably use the "single sender" approach.

EDIT, yes another student verifies this

I had to do the single sender verification on SendGrid in order to use my own API key.

UPDATE: another student says one way to do the verification process is through the settings menu:

Screenshot 2020-06-18 17 41 41

s2t2 commented 3 years ago

I have verified it is working. Need to setup single sender verification first. Then the following code should work. Also note the key with mail only didn't work. Full access API Key works. Would need to figure out the exact permissions needed to send an email.

# adapted from: 
# ... https://github.com/sendgrid/sendgrid-python/blob/main/USAGE.md
# ... https://github.com/sendgrid/sendgrid-python#with-mail-helper-class

from sendgrid import SendGridAPIClient

sg = SendGridAPIClient(api_key=API_KEY)

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

from_email = Email("prof.mj.rossetti+sendgrid@gmail.com") # NEEDS TO MATCH VERIFIED SINGLE SENDER
to_email = To("prof.mj.rossetti+receiver@gmail.com")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")

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

response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)

Need to also verify templates are still working: https://github.com/sendgrid/sendgrid-python/blob/main/use_cases/transactional_templates.md

s2t2 commented 3 years ago

Some students are seeing that SendGrid has disabled / suspended their account:

image

Resolution Steps:

s2t2 commented 2 years ago

Sendgrid keeps causing unnecessary issues for students.

Some students had their credentials revoked due to lack of use (even though we are actively using the credentials within the span of a single semester). This is a really dumb and investor deceptive practice on the part of Sendgrid that results in an artificially inflated number of accounts. I've emailed them about this and they refuse to fix the policy.

Other students have reached the max allowable emails limit:

The problem was that I went over the daily(or monthly?) limit of emails for a free sendgrid account. ... I got the issue fixed by using my groupmate's sendgrid credentials.

s2t2 commented 1 year ago

Using mailgun now