0

I am trying to send an email using win32com and have an object as body, such as:

outlook = win32com.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'receiver@email.com'
mail.Subject = 'subject of email'
mail.HtmlBody = table
mail.send

Where:

table = PrettyTable(['Header1', 'Header2'])
table.add_row(['row1col1', 'row1col2'])

However, I get the following error message:

TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object.

I have tried to get the string out of the table object as table.get_string() as well as str(table). In both cases, the entire table object is printed as a string on a single line (it loses the table format)

EDIT:

I can send the table via email if I send table.get_html_string() as email body, however, I'm losing all the borders, which is ok..ish, but not great ...

SECOND EDIT:

PrettyTable provides an API to print tables in Python and eventually, it returns an object.

Basically, I am trying to get that object (which when I call print table I get back a well formatted table) and dump it into an email

0 Answers0