Search code examples
pythonhtmlemailoutlookcss-tables

Insert table into mail body


I would like to add a table to a mail letter, but not as an attachment. Additional requirement is to fill some cells with colors, but I'm not able to find a solution for this.


Solution

  • The main issue was that HTML code was interpreted as plain text, not HTML. So, here is the answer:

    import win32com.client as win32
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = 'name@gmail.com'
    mail.Subject = 'Tadadada'
    mail.HTMLBody = '<h2>Place your HTML here</h2>'
    
    mail.Send()