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 at gmail.com richard.balbat at gmail.com
Fri Nov 8 23:06:38 CET 2013


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 < and > ???


# 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 at 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 at xxx.com","rbalbatov at 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><
 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>



More information about the Python-list mailing list