Mark6921260
Posts: 0
Joined: Mon Jun 09, 2014 3:35 pm

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

When I launched my app in the Apple, Google, and Windows app stores back in November 2014, the email function was working flawlessly. Then I get a notice that it is sending an email with a few characters of HTML code.
Image

So I checked the following:

  1. I opened the my app project in Appery.io. I tested the app by selecting the Test button at the top. When the emulator opened and my start screen was showing, I opened the Inspect Element from Google's Developer Tools to see what string was being passed into the variable that was used fro the Message section of the app. This showed exactly what was suppose to be showing.
    Image

  2. I next went to the mapping screen for the SendGrid email page of my app to check to make sure that this was correct. I saw that it was correctly mapped.
    Image

  3. I attempted to send myself an email via the test tab under ServicesSendGrid_MailSend. I copied the html for the message from the Google developer tools local storage for this variable highlighted in the first image above. Pressed test and the correct email was delivered.
    Image
    Image

  4. Lastly I created an HTML box on my app to display the message the variable is holding. When I tested this it showed exactly what the email should look like. Image
    Image

    Now, I'm stuck. I'm thinking it has to be something with the mapping, but why would it work a couple months ago and now stop working.
    Your support team has always helped me in the past. I hoping this situation will be the same.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Hi Mark -

You can try this steps:
1) Remove mapping and set it back;
2) Add next JS to your HTML parameter:
precodealert("HTML="+value);
return value;/code/pre

3) check the result;

Mark6921260
Posts: 0
Joined: Mon Jun 09, 2014 3:35 pm

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Hi Illya,

I deleted the mapping from Before Send:
Image

I then added back mapping and set it up just as how it had looked before.

I then added the code you wanted me to add and here is the image of the results.
This is exactly what it is suppose to be, but this is not what is being delivered.

Image

Unfortunately the email received showed the same broken HTML.

Image

So, now I am more confused, because I thought this was where the error was but I didn't know how to test it until you just showed me.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Well may be a bit off the tracks but generally when dealing with html it is preferred to translate special characters into html tags. For example this simple function can do it for you
code
function escapeHtml(text) {
return text
.replace(/&/g, "&")
&#46;replace(/</g, "<")
&#46;replace(/>/g, ">")
&#46;replace(/"/g, """)
&#46;replace(/'/g, "'");
}
/code

Translate the HTML using the above function and see if it helps

You can then try to narrow down / figure out what and where the html is breaking

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

And ya if dealing with bigger blocks of html / text this may be faster

code
function escapeHtml(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};

return text&#46;replace(/[&<>"']/g, function(m) { return map[m]; });
}
/code

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

And ya if dealing with bigger blocks of html / text this may be faster

code
function escapeHtml(text) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};

return text&#46;replace(/[&<>"']/g, function(m) { return map[m]; });
}
/code

Mark6921260
Posts: 0
Joined: Mon Jun 09, 2014 3:35 pm

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Hi M&M,
I thought I'd give it a shot even thought the HTML string I use works perfectly when I use it in the SendGrid Test tab.

While it didn't solve my problem it did narrow down my issue. The problem I am having is with the semicolon symbol. ";"
From the results of the test using your function all I got in the email was a <
as the first line goes: <p style="text-align: center;&
See how the email stops when it hits the semicolon.

If you look at my previous results:
See how again it stopped when it hits the semicolon

Just as one last test to make sure the semicolon was indeed the problem, I set my variable to plain text:
Lorem ipsum; dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend blandit lacinia.
And the resulting email only had Lorem ipsum
Proving that the semicolon is the problem.

Anybody have any ideas on how to deal with this?


M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Btw I don't know if this is relevant or something but I don't see a body tag. Wana check that out in the meantime

Mark6921260
Posts: 0
Joined: Mon Jun 09, 2014 3:35 pm

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

I gave the tag idea a try, but it didn't help. It's strange how it seems like it is reading the HTML like it a programming language where the semicolon is the end-of-command character. I tried all forms of character escaping to see if the semicolon could be read as HTML, but every time it stops at the first semicolon.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

SendGrid Email plugin has stopped working and is cutting off my message and only sending part of it.

Can I have the sample / test HTML that you have in the screenshot?

Return to “Issues”