简体   繁体   English

使用Outlook发送电子邮件时插入Python对象

[英]Insert Python Objects when sending email using Outlook

Simple question as the title:How can I insert or copy a Python object(like a matplotlib figure object just generated, not saved into the hard drive) into an email sending from Outlook? 标题为一个简单的问题:如何将Python对象(如刚刚生成的matplotlib图形对象,未保存到硬盘驱动器)插入或复制到Outlook发送的电子邮件中?

I'm not using SMTP module but operate Outlook via win32com.client. 我没有使用SMTP模块,而是通过win32com.client运行Outlook。 Some of current codes are as follows: 当前的一些代码如下:

import matplotlib.pyplot as plt
import win32com.client
import matplotlib.gridspec as gridspec

fig = plt.figure(figsize = (20,30))
gs = gridspec.GridSpec(5,2)

ax = plt.subplot(gs[0,0])
ax.plot(range(10))

obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "Daily Report of Volatility"
newMail.HTMLBody = "<h1> \
                        This is a test \
                    </h1> \
                    <p> \
                        I am a email-robot \
                    </p> \
                    "

newMail.To = "Kyle"

newMail.display()

Just want to insert the 'fig' object into the mail body. 只想在邮件正文中插入“ fig”对象。

Will appreciate any illustration! 将不胜感激任何插图! Thanks a lot! 非常感谢!

您需要生成图像,然后添加对消息正文的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM