Outputting hyperlinks to outlook
<p>I am trying to do the following,but the data finally that gets feeded to outlook is messedup,please look at the pastie links below for input,output and the code</p>

<p>1.read data from an xml using minidom 
2.and if there are hyperlinks ,am replacing with a regex to add ahref atribute
3.Outputting the data to outlook</p>

<pre><code>INPUT/Output:-
http://pastie.org/5408694
</code></pre>

<p>My code:-</p>

<p><a href="http://pastie.org/5408681" rel="nofollow">http://pastie.org/5408681</a></p>

<pre><code># Import package to access Outlook
import win32com.client
import re
import xml.dom.minidom as minidom
resultslis=[]

def getsanityresults(xmlfile):
  dom = minidom.parse(xmlfile)
  data=dom.getElementsByTagName('Sanity_Results')
  textnode = data[0].childNodes[0]
  testresults=textnode.data
  for line in testresults.splitlines():
    line = line.strip('\r,\n')
    line = re.sub(r'(http://[^\s]+|//[^\s]+|\\\\[^\s]+)', r'&lt;a href="\1"&gt;\1&lt;/a&gt;', line)
    print line     
    resultslis.append(line)
  return resultslis

def main ():
  file = open('results.xml','r')
  sanityresults=getsanityresults(file)
  print sanityresults
  msg_body=("&lt;HTML&gt;&lt;head&gt;&lt;/head&gt;"
        "&lt;body&gt; &lt;font face = \"Calibri\" &lt;br&gt;"
          "&lt;font face = \"Calibri\"%s&lt;br&gt;&lt;br&gt;"

        "&lt;/body&gt;&lt;/html&gt;"
        ) % (sanityresults)

  olMailItem = 0x0
  obj = win32com.client.Dispatch("Outlook.Application")
  newMail = obj.CreateItem(olMailItem)
  newMail.HTMLBody = msg_body
  newMail.display()

if __name__ == '__main__':
  main()
</code></pre>
