import fnmatch
import os
import lxml.html
import smtplib
import sys
matches = []
for root, dirnames, filenames in os.walk('C:\AUDI\New folder'):
for filename in fnmatch.filter(filenames, '*.html'):
matches.append(os.path.join(root, filename))
print filename
page = filename #the webpage to send
root = lxml.html.parse(page).getroot()
root.make_links_absolute()
content = lxml.html.tostring(root)
message = """From: sam <sam14@gmail.com>
To: sam <sam14@gmail.com>
MIME-Version: 1.0
Content-type: text/html
Subject: %s
%s""" %(page, content)
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.starttls()
smtpserver.login("sam14@gmail.com",os.environ["GPASS"])
smtpserver.sendmail('sam14@gmail.com', ['sam14@gmail.com'], message)
In the above code : Firstly, I am finding the *.html files in a directory. I am finding it, it is working fine for me. Later I want to send that html file as an email to some person. I am failing in that. Can someone suggest me how to do that ? print filename : is printing the list of html file in the directory, I have problem in sending the file as email. I am getting the error as :
File ".\task.py", line 15, in <module>
root = lxml.html.parse(page).getroot()
File "C:\Python27_3\lib\site-packages\lxml\html\__init__.py", line 789, in parse
return etree.parse(filename_or_url, parser, base_url=base_url, **kw)
File "lxml.etree.pyx", line 3310, in lxml.etree.parse (src\lxml\lxml.etree.c:72517)
File "parser.pxi", line 1791, in lxml.etree._parseDocument (src\lxml\lxml.etree.c:105979)
File "parser.pxi", line 1817, in lxml.etree._parseDocumentFromURL (src\lxml\lxml.etree.c:106278)
File "parser.pxi", line 1721, in lxml.etree._parseDocFromFile (src\lxml\lxml.etree.c:105277)
File "parser.pxi", line 1122, in lxml.etree._BaseParser._parseDocFromFile (src\lxml\lxml.etree.c:100227)
File "parser.pxi", line 580, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\lxml.etree.c:94350)
File "parser.pxi", line 690, in lxml.etree._handleParseResult (src\lxml\lxml.etree.c:95786)
File "parser.pxi", line 618, in lxml.etree._raiseParseError (src\lxml\lxml.etree.c:94818)
IOError: Error reading file 'report_email.html': failed to load external entity "report_email.html"