Closed thinkingserious closed 7 years ago
@thinkingserious I would like to work on this issue. Can you give me some pointers , on how to proceed?
@dibyadas,
Awesome!
The first step will be to create a proposal similar to this so that the community can review and provide feedback.
Thanks!
Elmer
@thinkingserious So, I just went through links for reference given in the issue description. But I still have some doubts. Can you help me with, what issue is this ticket addressing? And , whose response payload we are referring to and the kind of data validation we are talking about?
Thanks!
Dibya
Hi @dibyadas,
Thank you for the follow up!
For the Response object, I'm referring to something like this. It's a wrapper around HTTPResponse. The idea is that we can then customize the return object for specific SendGrid functionality. For now, it should have a status_code, body and headers. Right now, we return the original object directly.
The data validation portion does not have to be included in this iteration. But we should plan for it. The idea is that the helper should surface API errors where possible before the message is sent.
For error handling please see: https://github.com/sendgrid/sendgrid-python/issues/193
At a high level, we want a request object builder that we can pass to a function that will send the email.
For the use case described in the example, I'm thinking of something along the lines of this (both cases should be possible):
import sendgrid
sg = sendgrid.SendGridClient('SENDGRID_API_KEY')
from_email = Email('Test User', 'test@example.com')
to_email = Email('Test User', 'test@example.com')
subject = 'Hello World from the SendGrid Python Library!'
plain_text_content = 'Hello, Email!'
html_content = '<strong>Hello, Email!</strong>'
msg = create_single_email(from_email, to_email, subject, plain_text_content, html_content)
response = sg.send(msg)
or
import sendgrid
from sendgrid import SendGridMessage
sg = sendgrid.SendGridClient('SENDGRID_API_KEY')
msg = SendGridMessage()
msg.from_email = Email('Test User', 'test@example.com')
msg.to_email = Email('Test User', 'test@example.com')
msg.subject = 'Hello World from the SendGrid Python Library!'
msg.plain_text_content = 'Hello, Email!'
msg.html_content = '<strong>Hello, Email!</strong>'
response = sg.send(msg)
The first case demonstrates the use of the SendGridMessage builder create_single_email which this issue addresses.
The second case demonstrates the custom building of the SendGridMessage builder to allow for more advanced usage.
@thinkingserious Thanks a lot for your informative explanation! So what I have gathered from this is the following :- We can define a class which will act as a wrapper around the HTTPResponse Object, as you mentioned. So instead of returning the object directly, We can have :-
......
except timeout as e:
raise SendGridClientError(408, 'Request timeout')
response_obj = SendGridResponse(response.read() response.getcode(), response.getheaders())
return response_obj
......
Here the SendGridResponse is the class that we going to add.
And for the exception handling, we can also define SendGrid custom exceptions which can more be informative than standard python exceptions.
Does this look good?
Thanks!
Regards, Dibya
Looks good :)
Thanks @dibyadas!
@thinkingserious Once I am ready with proposed modifications, I will make a PR. :smile:
Thanks!
Awesome, thanks!
@thinkingserious I was having some problems registering an account in SendGrid. It said that my profile has been flagged as high risk. :confused: Am I doing something wrong there? Can you help me with this?
Thanks,
Regards, Dibya
What's your SendGrid username?
@thinkingserious dibyadas
@thinkingserious Thanks! I got a response from SendGrid support to activate my account. :smile:
@thinkingserious Unfortunately, I did not get any reply from Bogdan from SendGrid support. But then I remembered, I have Github Student Pack. So I registered a free account in it and now its working. :smile:
I cloned this repository and went through the code base. I saw that the response object returned here, for ex. , response = sg.client.mail.send.post(request_body=mail.get())
is a object of the Response class of python_http_client module. This class already has the status_code , body and headers of the response.
I also checked out this tree of the repo. It has a bit different code base. Am I missing something? Where should I make the changes? I installed the sendgrid module through pip. python version :- 3.5.2 pip version :- 9.0.1 sendgrid version :- 4.1.0
Sorry for the trouble!
Thanks, Regards, Dibya
Please branch off the current master (v4.1.0). That tree you are pointed to is no longer relevant.
@thinkingserious I guess then the Response object of the email is sorted. I just need to add the single email sending feature like you mentioned and the exception handling.
Thanks, Regards, Dibya
Correct, thanks!
This has been moved here.
What's your SendGrid username?
Hi @thinkingserious I am also facing the same issue, I just opened my new website as a Job portal & when I am registering it is not showing dashboard as it is saying that my profile is flagged as high risk, I don't why.
Plz help.
my registered email is admin@myjobpocket.com
Acceptance Criteria:
Reference: