办公自动化 - 创建消息文件
Office Automation - Create msg file
我正在尝试使用 Python 创建 Outlook 消息文件 (.msg) 文件,特别是来自 Flask。
这是我拥有的:
import win32com.client
def html2msg():
com_object = win32com.client.Dispatch('Outlook.Application')
com_file = com_object.CreateItem(0)
com_file.Subject = 'Subject'
com_file.HTMLBody = '<html><head></head><body><p>Test Email</p></body></html>'
com_file.SaveAs('new.msg')
com_file.Close(0)
当 运行 作为 Windows 中的用户时,或者当 Flask 应用程序作为用户 运行 手动作为用户时从 Flask 内部发起时,这工作正常...
当 运行 落后于 IIS
和 wfastcgi
时,问题就出现了:我收到这个非特定错误:
File "<COMObject Outlook.Application>", line 2, in CreateItem
pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)
我以前在 Word 中遇到过类似的(ish)问题,这是因为 com 对象在系统配置文件下 运行,并通过创建一个文件夹来解决:https://theether.net/kb/100120?id=100120
有没有人设法完成类似的事情?
The issue comes when it is run behind IIS with wfastcgi: I get this non-specific error:
Considerations for server-side Automation of Office 文章针对您遇到的错误说明如下:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
作为一种解决方法,您需要使用 Outlook 所基于的低级 API - 扩展 MAPI 或 API 周围的任何包装器,例如 Redemption .
如果您只处理 Exchange 服务器配置文件,请考虑使用 EWS,有关详细信息,请参阅 Start using web services in Exchange。
我正在尝试使用 Python 创建 Outlook 消息文件 (.msg) 文件,特别是来自 Flask。
这是我拥有的:
import win32com.client
def html2msg():
com_object = win32com.client.Dispatch('Outlook.Application')
com_file = com_object.CreateItem(0)
com_file.Subject = 'Subject'
com_file.HTMLBody = '<html><head></head><body><p>Test Email</p></body></html>'
com_file.SaveAs('new.msg')
com_file.Close(0)
当 运行 作为 Windows 中的用户时,或者当 Flask 应用程序作为用户 运行 手动作为用户时从 Flask 内部发起时,这工作正常...
当 运行 落后于 IIS
和 wfastcgi
时,问题就出现了:我收到这个非特定错误:
File "<COMObject Outlook.Application>", line 2, in CreateItem
pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)
我以前在 Word 中遇到过类似的(ish)问题,这是因为 com 对象在系统配置文件下 运行,并通过创建一个文件夹来解决:https://theether.net/kb/100120?id=100120
有没有人设法完成类似的事情?
The issue comes when it is run behind IIS with wfastcgi: I get this non-specific error:
Considerations for server-side Automation of Office 文章针对您遇到的错误说明如下:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
作为一种解决方法,您需要使用 Outlook 所基于的低级 API - 扩展 MAPI 或 API 周围的任何包装器,例如 Redemption .
如果您只处理 Exchange 服务器配置文件,请考虑使用 EWS,有关详细信息,请参阅 Start using web services in Exchange。