I have created a chart in matplotlib which I would like to send somewhat automatically.
I've converted the chart to png and then saved it as a variable as follows:
chart = io.BytesIO()
plt.savefig(chart, format='png')
chart.seek(0)
im = Image.open(chart)
def get_plot():
return im
It doesn't need to be in a png format to complete the task, I just thought saving it in that format would be the best way to store it.
I have then set up auto-generated email (today is a variable that holds the day's date):
def Emailer(text, subject, recipient):
outlook = win32com.client.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = subject
mail.HtmlBody = text
mail.Display(True)
MailSubject= "Auto test mail at "+today
MailInput=im
MailAdress='recipient@guyIwanttosendemailsto.com'
Emailer(MailInput, MailSubject, MailAdress )
Unfortunately when I run the code, I get an error message saying:
TypeError: Objects of type 'PngImageFile' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could)
If I didn't have the 'im' variable in the 'MailInput' the email works exactly as intended. I was wondering if any of you had some advice on how to finish this task?