trimmed string after replace function

D

denoxis

Hi,

I have a mystery to solve. It is a mystery because it happens randomly.


In the ASP page that is in question, I build a large string (no more
than 10K) which is basically an email template in HTML format. Then I
replace the parts with the values, which are also strings with the size
of 1-2 KB.

For example:

order_summary = generateOrderSummary() 'This HTML string is no more
than 4-5 KB

send_email (order_summary, to_sales_department) 'This email goes to
sales dept, they receive it OK.

email_body = readFromFile("HTML_email_template.html") ' This is 10KB

email_body = replace (email_body, "<!-- NAME -->", billing_name)

email_body = replace (email_body, "<!-- ORDER SUMMARY -->",
order_summary)

email_body = replace (email_body, "<!-- OTHER -->", other_stuff)

send_email (email_body, to_customer) ' They sometimes receive trimmed
order summary.



Here is the mystery: sometimes recipients complain that their order
confirmation is wrong because it seems order_summary part is trimmed.
They fw me the email and yes it was trimmed, however the rest of the
email is OK: just the order_summary in the middle of the email was
messed up. Since order_summary shows OK on the first email, and not on
the second email I concluded that there must be something with the
replace function. It doesn't happen a lot, there are only 2 known cases
out of couple thousands. It is not order-specific either, I place the
same order and order_summary shows OK.

Any suggestions on how to isolate the problem?
Have you encountered the same/similar problems with strings?

I use ASP 3.0 on IIS 6.0. Server is Windows 2003.

Thanks

Deniz
 
A

Anthony Jones

denoxis said:
Hi,

I have a mystery to solve. It is a mystery because it happens randomly.


In the ASP page that is in question, I build a large string (no more
than 10K) which is basically an email template in HTML format. Then I
replace the parts with the values, which are also strings with the size
of 1-2 KB.

For example:

order_summary = generateOrderSummary() 'This HTML string is no more
than 4-5 KB

send_email (order_summary, to_sales_department) 'This email goes to
sales dept, they receive it OK.

email_body = readFromFile("HTML_email_template.html") ' This is 10KB

email_body = replace (email_body, "<!-- NAME -->", billing_name)

email_body = replace (email_body, "<!-- ORDER SUMMARY -->",
order_summary)

email_body = replace (email_body, "<!-- OTHER -->", other_stuff)

send_email (email_body, to_customer) ' They sometimes receive trimmed
order summary.



Here is the mystery: sometimes recipients complain that their order
confirmation is wrong because it seems order_summary part is trimmed.
They fw me the email and yes it was trimmed, however the rest of the
email is OK: just the order_summary in the middle of the email was
messed up. Since order_summary shows OK on the first email, and not on
the second email I concluded that there must be something with the
replace function. It doesn't happen a lot, there are only 2 known cases
out of couple thousands. It is not order-specific either, I place the
same order and order_summary shows OK.

Any suggestions on how to isolate the problem?
Have you encountered the same/similar problems with strings?

It has been known that if the html body part of the email is not encoded
using quoted-printable encoding that white space gets inserted into html tag
names. When that happens the html output gets messed up.
 
D

Dave Anderson

denoxis said:
Any suggestions on how to isolate the problem?
Have you encountered the same/similar problems with strings?

What happens when you change this...
email_body = replace (email_body, "<!-- ORDER SUMMARY -->",
order_summary)

....to this?

email_body = replace(email_body, "<!-- ORDER SUMMARY -->",
Server.HTMLEncode(order_summary))
 
D

denoxis

If I do that I see the HTML source in the email! Doesn't HTMLEncode
change "<" to &lt; and ">" to &gt; etc? I don't want that, my email
*is* in HTML, I want to keep the tags so my email would be formatted
accordingly.

Deniz
 
D

denoxis

Dave said:
Right. But you did not try, so you did not find out if your content is
actually present.

I appreciate the suggestion, I did try it before I post my answer and
that's what I saw: piece of HTML source code in the middle of HTML
email, which would show correctly if it was real HTML. I thought you
suggested that those codes would translate back to normal HTML in the
email.
I made the suggestion so you could determine whether you were simply guilty
of writing sloppy HTML in the affected section. NOT VISIBLE does not equal
NOT THERE when it comes to HTML, after all. I suppose you can still [view
source] on the offending messages if you want to know for sure.

Sloppy HTML is less likely since it is generated in a loop for each
product. Something like:
....
"<tr><td>" & product_name & "</td><td>" & price & "</td><td>" & qty &
"</td></tr>"
....
I did make sure product names don't contain weird characters (such as <
and >) By looking at the source code of the email that is in question,
I see part of the HTML is missing with no trace

I did however one thing: adding linebreaks in the HTML-generating loop
(otherwise there could be a very long line depending on the order size,
which is actually reason of some of the bounce-backs) So maybe it is
line-length related issue. We will see if adding '& vbcrlf' to the end
of the code above helps.

Thanks for the answers

Deniz
 
A

Anthony Jones

denoxis said:
Dave said:
Right. But you did not try, so you did not find out if your content is
actually present.

I appreciate the suggestion, I did try it before I post my answer and
that's what I saw: piece of HTML source code in the middle of HTML
email, which would show correctly if it was real HTML. I thought you
suggested that those codes would translate back to normal HTML in the
email.
I made the suggestion so you could determine whether you were simply guilty
of writing sloppy HTML in the affected section. NOT VISIBLE does not equal
NOT THERE when it comes to HTML, after all. I suppose you can still [view
source] on the offending messages if you want to know for sure.

Sloppy HTML is less likely since it is generated in a loop for each
product. Something like:
...
"<tr><td>" & product_name & "</td><td>" & price & "</td><td>" & qty &
"</td></tr>"
...
I did make sure product names don't contain weird characters (such as <
and >) By looking at the source code of the email that is in question,
I see part of the HTML is missing with no trace

I did however one thing: adding linebreaks in the HTML-generating loop
(otherwise there could be a very long line depending on the order size,
which is actually reason of some of the bounce-backs) So maybe it is
line-length related issue. We will see if adding '& vbcrlf' to the end
of the code above helps.

Have you yet confirmed whether the HTML body part is being encoded as
quoted-printable. I said this already but you didn't respond. If you
haven't you could well save yourself a lot of time but just checking. It is
the most likely cause of your problem.
 
D

denoxis

Anthony,

I am sorry, I didn't read the answer carefully, I thought you were
suggesting the same thing. Actually you may be pointing out to the core
of the problem. I thought these kind of encodings were done
automatically by the email sender component, however I just checked the
reference for it and it says I have to set ContentTransferEncoding
property to "quoted-printable" to have quoted-printable. So I will
definitely try that.

Thanks for the followup!!!

Deniz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top