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

Send a Single Email to a Single Recipient #224

Closed
thinkingserious opened this issue Sep 23, 2016 · 18 comments
Closed

Send a Single Email to a Single Recipient #224

thinkingserious opened this issue Sep 23, 2016 · 18 comments
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@thinkingserious
Copy link
Contributor

Acceptance Criteria:

  • A email object that represents the response body payload
  • A mail object that handles sending email objects, data validation and error handling

Reference:

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: task labels Sep 23, 2016
@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap and removed type: task labels Apr 28, 2017
@dibyadas
Copy link

@thinkingserious I would like to work on this issue. Can you give me some pointers , on how to proceed?

@thinkingserious
Copy link
Contributor Author

@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

@dibyadas
Copy link

dibyadas commented May 17, 2017

@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

@thinkingserious
Copy link
Contributor Author

Hi @dibyadas,

Thank you for the follow up!

  1. 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.

  2. 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.

  3. For error handling please see: Improved error handling #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.

@dibyadas
Copy link

@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

@thinkingserious
Copy link
Contributor Author

Looks good :)

Thanks @dibyadas!

@dibyadas
Copy link

@thinkingserious Once I am ready with proposed modifications, I will make a PR. 😄

Thanks!

@thinkingserious
Copy link
Contributor Author

Awesome, thanks!

@dibyadas
Copy link

@thinkingserious I was having some problems registering an account in SendGrid. It said that my profile has been flagged as high risk. 😕 Am I doing something wrong there?
Can you help me with this?

Thanks,

Regards, Dibya

@thinkingserious
Copy link
Contributor Author

What's your SendGrid username?

@dibyadas
Copy link

@thinkingserious dibyadas

@dibyadas
Copy link

@thinkingserious Thanks! I got a response from SendGrid support to activate my account. 😄

@dibyadas
Copy link

@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. 😄

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

@thinkingserious
Copy link
Contributor Author

Please branch off the current master (v4.1.0). That tree you are pointed to is no longer relevant.

@dibyadas
Copy link

@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

@thinkingserious
Copy link
Contributor Author

Correct, thanks!

@thinkingserious
Copy link
Contributor Author

This has been moved here.

@rukmanigupta
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

3 participants