setting content with a value of
'something\nsomething'
will not format correctly where as
'something\n something'
will format correctly in the received email.
1, Set up a mail object assigning the content as follows:
content=Content('text/plain','something\nsomething')
I was creating an email whose contents is created by concatenating a string from popping off a list variable. I spent a lot of time comparing the difference of when I hardcoded the value of content versus using my code. Only after viewing debug printing of the content body was I able to discern this subtlety.
Hello @qaturner,
I'm not sure if this is a library or API issue. I have added this to our backlog for further investigation. Thanks for bringing this to our attention!
With Best Regards,
Elmer
I am investigating this as part of the Hacktoberfest fun.
It seems that this is an API/backend issue. This is what I get when sending those to cases mentioned by qaturner:
Content-type: multipart/alternative; boundary="----------=_1538496091-12812-69"
------------=_1538496091-12812-69
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
this is good
case
------------=_1538496091-12812-69
Content-Type: text/html; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
<html><body>
<p>this is good</p>
<pre>case</pre>
------------=_1538496091-12812-69--
Content-type: multipart/alternative; boundary="----------=_1538496076-20484-861"
------------=_1538496076-20484-861
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
this is bad
case
------------=_1538496076-20484-861
Content-Type: text/html; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
<html><body>
<p>this is bad case</p>
</body></html>
------------=_1538496076-20484-861--
So it looks like the html alternative gets incorrect newline.
I am not ure if there is anything more I can do. If so, please give me some hints
Thanks for the detailed report @meahow!
@kylearoberts,
When you get a moment could you take a look at this one? Looks like we have a server side bug here.
With Best Regards,
Elmer
Hello @meahow
I'm working on testing this issue you brought up and could use your help in making sure I am testing it the correct way. So far I have not been able to replicate the issue.
First test:
curl -X POST \
https://api.sendgrid.com/v3/mail/send \
-H 'Authorization: Bearer XXXX' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{
"personalizations": [
{
"to": [
{
"email": "[email protected]"
}
]
}
],
"from": {
"email": "[email protected]",
"name": "Kyle Roberts"
},
"reply_to": {
"email": "[email protected]",
"name": "Kyle Roberts"
},
"subject": "Testing Mail Send",
"content": [
{
"type": "text/plain",
"value": "this is a\ntest"
},
{
"type": "text/html",
"value": "<html><body><p>this is a</p>\n<p>test</p></body></html>"
}
]
}'
In this first test I get:
--181c98cc1e5302f3452a0e89cd64d02bfac94c51b691bc48c875d0fc5891
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
Mime-Version: 1.0
this is a
test
--181c98cc1e5302f3452a0e89cd64d02bfac94c51b691bc48c875d0fc5891
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
Mime-Version: 1.0
<html><body><p>this is a</p>
<p>test</p></body></html>
--181c98cc1e5302f3452a0e89cd64d02bfac94c51b691bc48c875d0fc5891--
Can you share exactly what you did to cause the issue. I want to make sure I am testing this correctly.
@thinkingserious
If I am testing this correctly their may be an issue with the library.
@kylearoberts
Just to be clear, I did not bring this issue up, I just investigated it :)
Anyway.
How I reproduced it is I ran the very simplest example for sendgrid in python.
It sends this json to the server (at least this is what I get from sendgrid.helpers.mail.Mail.get() ):
{"content": [{"type": "text/plain", "value": "this is bad\ncase"}],
"from": {"email": "[email protected]"},
"personalizations": [{"to": [{"email": "[email protected]"}]}],
"subject": "sendgrida test"}
But... when I was trying to reproduce it for the sake of this message, I was not able to repeat that same issue again.
So maybe you fixed it already ? :)
@qaturner Can you verify that ?
@meahow
Sorry for my confusion and thank you for your help with the issue.
@qaturner
Are you still able to create this issue? If so please let us know with details of how so we can replicate the issue and get it to our engineers.