BSAFH
BSAFH

Reputation: 745

HTML formatting issues with python smtplib and Outlook 2010

I am generating html files using elementtree.ElementTree.dump on an Element. The files look ok in all browsers, and the underlying code within the files looks fine (no unclosed brackets or anything).

When I send an email to Outlook 2010 via smtplib, I am seeing weird formatting issues. These issues will be 100% repeatable, so the issue is logical. Here is an example:

<table b="" order="1">

That is from the source code of a HTML email I sent myself. It is correctly written as:

<table border="1">

within the original source code.

If in Outlook I write a HTML email using the original HTML as source, it correctly formats. (New email-attach html file->insert as text)

Is the issue going to be Outlook or Python? The function I used for reading the html file and sending is below.

def email_Report(mailOptions):
  reportName = time.strftime("%Y%m%d.%H%M") + ".html"
  ElementTree(mailOptions['report']).write("/home/%s/%s" %(mailOptions['username'],reportName))
  #Set sender and receiver to the user building the report.
  mailaddr = '%[email protected]' %(mailOptions['username'])
  #Access the report file. Added binary in case we ever use code on Windows
  filename = "/home/%s/%s" % (mailOptions['username'], reportName)
  open_file = open(filename, 'rb')
  emsg = MIMEText(open_file.read(), 'html')
  open_file.close()
  emsg['Subject'] = "Report for %s generated by %s %s" % (mailOptions['zone'], mailOptions['username'], time.strftime("%d%m%Y-%H%M"))
  emsg['To'] = mailaddr
  emsg['From'] = mailaddr
  #Hostname can be a parameter to SMTP method if localhost isn't listening
  sc = smtplib.SMTP()
  sc.connect()
  sc.sendmail(mailaddr, mailaddr, emsg.as_string())
  sc.close()
  return 

The HTML is extremely simple. No CSS, no title or head tags etc. Just html->body->table->tr->th->(newrow)->td->td etc. Could I have overlooked something like encoding/escaping? Do I have to use mime multipart? I am using Python 2.4.3 and can't use any module that didn't come stock.

Upvotes: 0

Views: 1883

Answers (1)

malliemcg
malliemcg

Reputation: 136

Are you sure you're not running into the 990 character limit for mail servers as per workaround for the 990 character limitation for email mailservers

Upvotes: 2

Related Questions