When I send email as HTML, why do erroneous whitespaces getintroduced to the HTML source and a few <

R

richard.balbat

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 = "(e-mail address removed)"

content = MIMEMultipart()

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


content['From'] = fromaddr
recipient_list = ["(e-mail address removed)","(e-mail address removed)"]
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><fontcolor="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><fontcolor="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><fontcolor="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>
 
D

dieter

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.
 
R

Richard Balbat

rich writes:
Dieter, you were right!!! I broke up the string by inserting CRLF before I reached 72 chars / line. Problem solved!






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.
 

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

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top