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

text/plain must precede text/html content #451

Closed
hugomallinson opened this issue Oct 27, 2017 · 3 comments
Closed

text/plain must precede text/html content #451

hugomallinson opened this issue Oct 27, 2017 · 3 comments
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap

Comments

@hugomallinson
Copy link

Issue Summary

Requests to send mail with both plain text and HTML content fail if the HTML content is specified first.

Code

sg = sendgrid.SendGridAPIClient(apikey=sendgrid_key)
mail = Mail()
from_email = Email("from@email.com")
to_email = Email("to@email.com")
subject = "Sending with SendGrid is Fun"
per = Personalization()
mail.from_email = from_email
mail.subject = subject
html_content = Content("text/html", "<html><body>some text here</body></html>")
plain_content = Content("text/plain", "and easy to do anywhere, even with Python")

### Add plain content first
mail.add_content(plain_content)

### Add HTML content next
mail.add_content(html_content)

per.add_to(to_email)
mail.add_personalization(per)
response = sg.client.mail.send.post(request_body=mail.get())

Steps to Reproduce

  1. The above code works properly, but if you reverse the order of the add_content lines, http-client throws a BadRequestsError

Expected Result

The library should sort content into the order that the API expects. (I'm not clear why the order should matter to the API—perhaps this should be fixed there instead.)

Technical details:

  • sendgrid-python Version: master (latest commit: [b12728a])
  • Python Version: 2.7.13
@dsouzarc
Copy link
Contributor

@hugomallinson Interesting find - I hope I fixed that issue in this Pull Request

@mbernier mbernier removed difficulty: hard fix is hard in difficulty difficulty: medium fix is medium in difficulty difficulty: very hard fix is very hard in difficulty labels Oct 27, 2017
@gabrielkrell
Copy link
Contributor

Very interesting. In addition to @dsouzarc's fix, I think this should be either changed in the API or mentioned in the docs.

@dsouzarc
Copy link
Contributor

dsouzarc commented Nov 1, 2017

It should probably be in the API otherwise we'd have to implement this fix in every client/SDK, but I wonder what's causing the issue.

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap status: work in progress Twilio or the community is in the process of implementing hacktoberfest difficulty: medium fix is medium in difficulty labels Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

5 participants