Using B64 to Encode Image in Email

  dataframe, matplotlib, python
#
 plt.savefig(f'P:AdvisorySub debt DDSub Debt Cash{datetoday}.png',bbox_inches='tight')

'''Encode in b64 (to send in E-mail Body)'''
#
 data = open(f'P:AdvisorySub debt DDSub Debt Cash{datetoday}.png','rb').read()
 data_base64 = base64.b64encode(data)
 data_base64 = data_base64.decode()
 chart = f'<img src="data:P:AdvisorySub debt DDSub Debt Cash{datetoday}/png;base64,' + data_base64 + '">'
 open('output-png.html', 'w').write(chart)

'''Send E-mail'''
#
 def send_email(table):
      logging.info('Creating email')
      outlook = win32.Dispatch('outlook.application')
      mail = outlook.CreateItem(0)
      # recipient_list = 
      logging.info(f'Sending email to {recipient_list}')
      mail.To = recipient_list
      mail.Subject = f"Financials Cash Sheet: {todaydate} [UPDATED]"
      mail.HTMLBody = table
      mail.Send()

 send_email(sqltable)
 logging.info('Successfully completed')

I think I am almost there, but when I set mail.HTMLBody = table + chart, It sends an email with the table (not shown in the code here) and a red x object instead of my image.

What am I doing wrong?

Source: Python Questions

LEAVE A COMMENT