Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58872 > unrolled thread

When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???

Started byrichard.balbat@gmail.com
First post2013-11-08 14:06 -0800
Last post2013-11-10 04:17 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ??? richard.balbat@gmail.com - 2013-11-08 14:06 -0800
    Re: When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ??? dieter <dieter@handshake.de> - 2013-11-09 08:29 +0100
      Re: When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ??? Richard Balbat <richard.balbat@gmail.com> - 2013-11-11 18:02 -0800
    Re: When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ??? Walter Hurry <walterhurry@lavabit.com> - 2013-11-10 04:17 +0000

#58872 — When I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???

Fromrichard.balbat@gmail.com
Date2013-11-08 14:06 -0800
SubjectWhen I send email as HTML, why do erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???
Message-ID<aa3a285b-b526-4f02-9cfa-90ef4e3daf3a@googlegroups.com>
I have the following script that reads in an HTML file containing a table then sends it out via email with a content type of text/html.

For some reason a few erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???


# Import libraries
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText

buffer_results = open('results.html', 'r')
HTMLContent = buffer_results.read()
print repr(HTMLContent)
buffer_results.close()	

# Send out email notification stating the test execution is completed. 
COMMASPACE = ', '
fromaddr = "xxx@aaa.com"

content = MIMEMultipart()

body = MIMEMultipart('alternative')
#body.attach(MIMEText(msgtext))
body.attach(MIMEText(HTMLContent, 'html'))
content.attach(body)


content['From'] = fromaddr
recipient_list = ["rbalbatov@xxx.com","rbalbatov@yyy.com"]
content['To'] = COMMASPACE.join(recipient_list)
content['Subject'] = 'Hello World'
server = smtplib.SMTP('<mail server>', 25)
server.ehlo()
server.ehlo()
text = content.as_string()
server.sendmail(fromaddr, recipient_list, text)




Contents of results.html

<html><head><title>Test Campaign Results</title></head><body><p>SoapUI regression testing has completed against the following: <br/><br/> Environment: Auto.QA<br/>Build: test<br/>Detailed results can be found here: http://xxxx-AUTO1.xxxx.xxx/SoapUITestResults/Auto.QA-2013-6-11_22-54-50<br/><br/></p><table border="1"><tr><th>SoapUI Project (WSDL/WADL)</th><th>Total</th><th>Pass</th><th>Failure</th><th>Pass Percentage</th></tr><tr><td>acceptancePartnerEndpointWSDefinition-soapui-project.xml</td><td>7</td><td><font color="green">7</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>AIM-Automation.xml</td><td>25</td><td><font color="green">23</font></td><td><font color="red">2</font></td><td>92.00%</td></tr><tr><td>ATM-Automation.xml</td><td>41</td><td><font color="green">33</font></td><td><font color="red">8</font></td><td>80.49%</td></tr><tr><td>xxxxxxxx-B2B-GW-soapui-project.xml</td><td>53</td><td><font color="green">52</font></td><td><font color="red">1</font></td><td>98.11%</td></tr><tr><td>CheckoutManager-soapui-project.xml</td><td>59</td><td><font color="green">58</font></td><td><font color="red">1</font></td><td>98.31%</td></tr><tr><td>customerManagerWSDefinition-Entity-MGR-soapui-project.xml</td><td>9</td><td><font color="green">7</font></td><td><font color="red">2</font></td><td>77.78%</td></tr><tr><td>EMP-Automation.xml</td><td>2</td><td><font color="green">2</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>EntityManager---Acceptance-Location-soapui-project.xml</td><td>12</td><td><font color="green">3</font></td><td><font color="red">9</font></td><td>25.00%</td></tr><tr><td>xxxxxxxxx-gateway-soapui-project.xml</td><td>28</td><td><font color="green">27</font></td><td><font color="red">1</font></td><td>96.43%</td></tr><tr><td>iinDatabaseWSDefinition-Payment-BIN-DB-soapui-project.xml</td><td>1</td><td><font color="green">1</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>LM-ST-Automation.xml</td><td>17</td><td><font color="green">2</font></td><td><font color="red">15</font></td><td>11.76%</td></tr><tr><td>Loyalty-MGW-soapui-project.xml</td><td>34</td><td><font color="green">27</font></td><td><font color="red">7</font></td><td>79.41%</td></tr><tr><td>xxxxxxx-Automation.xml</td><td>33</td><td><font color="green">29</font></td><td><font color="red">4</font></td><td>87.88%</td></tr><tr><td>MobileGateway-soapui-project.xml</td><td>227</td><td><font color="green">202</font></td><td><font color="red">25</font></td><td>88.99%</td></tr><tr><td>xxxxxxxxxxxx-MGW-soapui-project.xml</td><td>23</td><td><font color="green">12</font></td><td><font color="red">11</font></td><td>52.17%</td></tr><tr><td>xxxx-Automation.xml</td><td>42</td><td><font color="green">37</font></td><td><font color="red">5</font></td><td>88.10%</td></tr><tr><td>xxxx-gateway-soapui-project.xml</td><td>32</td><td><font color="green">10</font></td><td><font color="red">22</font></td><td>31.25%</td></tr><tr><td>OM-Automation.xml</td><td>53</td><td><font color="green">53</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>P-xxxxxx-PAYPRO-AP-Automation.xml</td><td>17</td><td><font color="green">9</font></td><td><font color="red">8</font></td><td>52.94%</td></tr><tr><td>P-xxxxxx-POS-Automation.xml</td><td>124</td><td><font color="green">31</font></td><td><font color="red">93</font></td><td>25.00%</td></tr><tr><td>P-xxxxxx-VP3-Automation.xml</td><td>20</td><td><font color="green">11</font></td><td><font color="red">9</font></td><td>55.00%</td></tr><tr><td>PAM-Automation.xml</td><td>20</td><td><font color="green">13</font></td><td><font color="red">7</font></td><td>65.00%</td></tr><tr><td>partnerEndpointWSDefinition-soapui-project.xml</td><td>6</td><td><font color="green">6</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>PAYPRO-AP-Automation.xml</td><td>121</td><td><font color="green">121</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>PAYPRO-IP-Automation.xml</td><td>35</td><td><font color="green">26</font></td><td><font color="red">9</font></td><td>74.29%</td></tr><tr><td>POS-Automation.xml</td><td>156</td><td><font color="green">104</font></td><td><font color="red">52</font></td><td>66.67%</td></tr><tr><td>SecureCloud-soapui-project.xml</td><td>25</td><td><font color="green">1</font></td><td><font color="red">24</font></td><td>4.00%</td></tr><tr><td>Security-Manager-for-Customer-Manager-soapui-project.xml</td><td>5</td><td><font color="green">0</font></td><td><font color="red">5</font></td><td>0.00%</td></tr><tr><td>Security-Manager-for-Mobile-Gateway-soapui-project.xml</td><td>21</td><td><font color="green">0</font></td><td><font color="red">21</font></td><td>0.00%</td></tr><tr><td>SecurityManager-for-CustomerPortal-soapui-project.xml</td><td>15</td><td><font color="green">0</font></td><td><font color="red">15</font></td><td>0.00%</td></tr><tr><td>xxxxxxxx-Automation.xml</td><td>30</td><td><font color="green">2</font></td><td><font color="red">28</font></td><td>6.67%</td></tr><tr><td>SMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>SSP-REST-API.xml</td><td>45</td><td><font color="green">15</font></td><td><font color="red">30</font></td><td>33.33%</td></tr><tr><td>xxxxxx-MGW-soapui-project.xml</td><td>52</td><td><font color="green">3</font></td><td><font color="red">49</font></td><td>5.77%</td></tr><tr><td>TM-EMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>TM-SMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>TMP-Automation.xml</td><td>70</td><td><font color="green">3</font></td><td><font color="red">67</font></td><td>4.29%</td></tr><tr><td>TMPAM-Automation.xml</td><td>21</td><td><font color="green">1</font></td><td><font color="red">20</font></td><td>4.76%</td></tr><tr><td>TMPP-AP-Automation.xml</td><td>121</td><td><font color="green">2</font></td><td><font color="red">119</font></td><td>1.65%</td></tr><tr><td>TMPP-IP-Automation.xml</td><td>26</td><td><font color="green">1</font></td><td><font color="red">25</font></td><td>3.85%</td></tr><tr><td>Transaction-Manager---Acceptance-Location-soapui-project.xml</td><td>11</td><td><font color="green">0</font></td><td><font color="red">11</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Customer-Manager(SEC)-soapui-project.xml.xml</td><td>5</td><td><font color="green">0</font></td><td><font color="red">5</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Customer-Portal-soapui-project.xml.xml</td><td>15</td><td><font color="green">0</font></td><td><font color="red">15</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-iinDatabase-Payment-BIN-DB-soapui-project.xml</td><td>1</td><td><font color="green">0</font></td><td><font color="red">1</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Mobile-Gateway.xml</td><td>32</td><td><font color="green">3</font></td><td><font color="red">29</font></td><td>9.38%</td></tr><tr><td>TX-OM-Automation.xml</td><td>53</td><td><font color="green">4</font></td><td><font color="red">49</font></td><td>7.55%</td></tr><tr><td>XXXXXXX-Automation.xml</td><td>34</td><td><font color="green">2</font></td><td><font color="red">32</font></td><td>5.88%</td></tr><tr><td>Grand Totals</td><td>1785</td><td><font color="green">943</font></td><td><font color="red">842</font></td><td>52.83%</td></tr></table></body></html>

This is what I see in outlook when I view source. Notice the delta. Any idea why this is occurring?

color="green">9</font></td><td><font color="red">8</font></td><td>52.94%</td></tr><tr><td>P-xxxxxx-POS-Automation.xml</td><td>124</td><td><font color="green">31</font></td><td><font color="red">93</font></td><td>25.00%</td></tr><tr><td>P-xxxxxx-VP3-Automation.xml</td><td>20</td><td><font color="green">11</font></td><td><font color="red">9</font></td><td>55.00%</td></tr><tr><td>PAM-Automation.xml</td><td>20</td><td><font color="green">13</font></td><td><font color="red">7</font></td><td>65.00%</td></tr><tr><td>partnerEndpointWSDefinition-soapui-project.xml</td><td>6</td><td><font color="green">6</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>PAYPRO-AP-Automation.xml</td><td>121</td><td><font color="green">121</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>PAYPRO-IP-Automation.xml</td><td>35</td><td><font color="green">26</font></td><td><font color="red">9</font></td><td>74.29%</td></tr><tr><td>POS-Automation.xml</td><td>156</td><td><font color="green">104</font></td><td><font color="red">52</font></td><td>66.67%</td></tr><tr><td>SecureCloud-soapui-project.xml</td><td>25</td><td><font color="green">1</font></td><td><font color="red">24</font></td><td>4.00%</td></tr><tr><td>Security-Manager-for-Customer-Manager-soapui-project.xml</td><td>5</td><td><font color="green">0</font></td><td><font color="red">5</font></td><td>0.00%</td></tr><tr><td>Security-Manager-for-Mobile-Gateway-soapui-project.xml</td><td>21</td><td><font color="green">0</font></td><td><font color="red">21</font></td><td>0.00%</td></tr><tr><td>SecurityManager-for-CustomerPortal-soapui-project.xml</td><td>15</td><td><font color="green">0</font></td><td><font color="red">15</font></td><td>0.00%</td></tr><tr><td>x
 xxxxxxx-Automation.xml</td><td>30</td><td><font color="green">2</font></td><td><font color="red">28</font></td><td>6.67%</td></tr><tr><td>SMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>SSP-REST-API.xml</td><td>45</td><td><font color="green">15</font></td><td><font color="red">30</font></td><td>33.33%</td></tr><tr><td>xxxxxx-MGW-soapui-project.xml</td><td>52</td><td><font color="green">3</font></td><td><font color="red">49</font></td><td>5.77%</td></tr><tr><td>TM-EMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>TM-SMP-Automation.xml</td><td>2</td><td><font color="green">0</font></td><td><font color="red">2</font></td><td>0.00%</td></tr><tr><td>TMP-Automation.xml</td><td>70</td><td><font color="green">3</font></td><td><font color="red">67</font></td><td>4.29%</td></tr><tr><td>TMPAM-Automation.xml</td><td>21</td>
 <td><font color="green">1</font></td><td><font color="red">20</font></td><td>4.76%</td></tr><tr><td>TMPP-AP-Automation.xml</td><td>121</td><td><font color="green">2</font></td><td><font color="red">119</font></td><td>1.65%</td></tr><tr><td>TMPP-IP-Automation.xml</td><td>26</td><td><font color="green">1</font></td><td><font color="red">25</font></td><td>3.85%</td></tr><tr><td>Transaction-Manager---Acceptance-Location-soapui-project.xml</td><td>11</td><td><font color="green">0</font></td><td><font color="red">11</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Customer-Manager(SEC)-soapui-project.xml.xml</td><td>5</td><td><font color="green">0</font></td><td><font color="red">5</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Customer-Portal-soapui-project.xml.xml</td><td>15</td><td><font color="green">0</font></td><td><font color="red">15</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-iinDatabase-Payment-BIN-DB-soapui-project.xml</td>&lt;
 td&gt;1</td><td><font color="green">0</font></td><td><font color="red">1</font></td><td>0.00%</td></tr><tr><td>Transaction-Manager-for-Mobile-Gateway.xml</td><td>32</td><td><font color="green">3</font></td><td><font color="red">29</font></td><td>9.38%</td></tr><tr><td>TX-OM-Automation.xml</td><td>53</td><td><font color="green">4</font></td><td><font color="red">49</font></td><td>7.55%</td></tr><tr><td>XXXXXXX-Automation.xml</td><td>34</td><td><font color="green">2</font></td><td><font color="red">32</font></td><td>5.88%</td></tr><tr><td>Grand Totals</td><td>1785</td><td><font color="green">943</font></td><td><font color="red">842</font></td><td>52.83%</td></tr></table></body></html>

[toc] | [next] | [standalone]


#58910

Fromdieter <dieter@handshake.de>
Date2013-11-09 08:29 +0100
Message-ID<mailman.2281.1383982152.18130.python-list@python.org>
In reply to#58872
richard.balbat@gmail.com writes:

> I have the following script that reads in an HTML file containing a table then sends it out via email with a content type of text/html.
>
> For some reason a few erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???
> ...
> Contents of results.html
>
> <html><head><title>Test Campaign Results</title></head><body><p>SoapUI regression testing has completed against the following: <br/><br/> Environment: Auto.QA<br/>Build: test<br/>Detailed results can be found here: http://xxxx-AUTO1.xxxx.xxx/SoapUITestResults/Auto.QA-2013-6-11_22-54-50<br/><br/></p><table border="1"><tr><th>SoapUI Project (WSDL/WADL)</th><th>Total</th><th>Pass</th><th>Failure</th><th>Pass Percentage</th></tr><tr><td>acceptancePartnerEndpointWSDefinition-soapui-project.xml</td><td>7</td><td><font color="green">7</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>AIM-Automation.xml</td><td>25</td><td><font color="green">23</font></td><td><font color="red">2</font></td><td>92.00%</td></tr><tr><td>ATM-Automation.xml</td><td>41</td><td><font color="green
> ...

I suggest to log the generated email (before sending) to verify whether
the transformation happens in your script or somewhere during the
email transport.


The email transport protocol ("SMTP" - "Simple Mail Transfer Protocol")
in principle imposes quite a strict limitation on line length
(72 characters, when I remember right). Your html input has much larger
lines - maybe, they are broken up somewhere - at the cost of spurious
whitespace. Usually, a "Content-Transfer-Encoding" is used
to satisfy the line length limitation. If this is quoted printable,
then reading the text undecoded, it may seem to have additional
characters (whitespace and control characters).

I have no idea what may replace "<" and ">" by html entity references.

[toc] | [prev] | [next] | [standalone]


#59138

FromRichard Balbat <richard.balbat@gmail.com>
Date2013-11-11 18:02 -0800
Message-ID<7092deaf-9193-4d0e-a7dd-b34b12ea16f6@googlegroups.com>
In reply to#58910
On Saturday, November 9, 2013 2:29:00 AM UTC-5, dieter wrote:
> rich writes:
> Dieter, you were right!!! I broke up the string by inserting CRLF before I reached 72 chars / line. Problem solved!
> 
> 
> > I have the following script that reads in an HTML file containing a table then sends it out via email with a content type of text/html.
> 
> >
> 
> > For some reason a few erroneous whitespaces get introduced to the HTML source and a few < > chars get converted to &lt; and &gt; ???
> 
> > ...
> 
> > Contents of results.html
> 
> >
> 
> > <html><head><title>Test Campaign Results</title></head><body><p>SoapUI regression testing has completed against the following: <br/><br/> Environment: Auto.QA<br/>Build: test<br/>Detailed results can be found here: http://xxxx-AUTO1.xxxx.xxx/SoapUITestResults/Auto.QA-2013-6-11_22-54-50<br/><br/></p><table border="1"><tr><th>SoapUI Project (WSDL/WADL)</th><th>Total</th><th>Pass</th><th>Failure</th><th>Pass Percentage</th></tr><tr><td>acceptancePartnerEndpointWSDefinition-soapui-project.xml</td><td>7</td><td><font color="green">7</font></td><td><font color="red">0</font></td><td>100.00%</td></tr><tr><td>AIM-Automation.xml</td><td>25</td><td><font color="green">23</font></td><td><font color="red">2</font></td><td>92.00%</td></tr><tr><td>ATM-Automation.xml</td><td>41</td><td><font color="green
> 
> > ...
> 
> 
> 
> I suggest to log the generated email (before sending) to verify whether
> 
> the transformation happens in your script or somewhere during the
> 
> email transport.
> 
> 
> 
> 
> 
> The email transport protocol ("SMTP" - "Simple Mail Transfer Protocol")
> 
> in principle imposes quite a strict limitation on line length
> 
> (72 characters, when I remember right). Your html input has much larger
> 
> lines - maybe, they are broken up somewhere - at the cost of spurious
> 
> whitespace. Usually, a "Content-Transfer-Encoding" is used
> 
> to satisfy the line length limitation. If this is quoted printable,
> 
> then reading the text undecoded, it may seem to have additional
> 
> characters (whitespace and control characters).
> 
> 
> 
> I have no idea what may replace "<" and ">" by html entity references.

[toc] | [prev] | [next] | [standalone]


#58984

FromWalter Hurry <walterhurry@lavabit.com>
Date2013-11-10 04:17 +0000
Message-ID<l5n1cs$j35$1@news.albasani.net>
In reply to#58872
On Fri, 08 Nov 2013 14:06:38 -0800, richard.balbat wrote:

> I have the following script that reads in an HTML file containing a
> table then sends it out via email with a content type of text/html.
> 
> For some reason a few erroneous whitespaces get introduced to the HTML
> source and a few < > chars get converted to &lt; and &gt; ???
> 
Perhaps it might ne a better idea not to send HTML emails at all. Or if 
you must, please don't send them to this list.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web