【问题标题】:Creating Outlook template (.oft) file in an ASP.Net MVC application在 ASP.Net MVC 应用程序中创建 Outlook 模板 (.oft) 文件
【发布时间】:2022-04-03 15:08:25
【问题描述】:
我需要在 ASP.Net MVC4 Web 应用程序(使用 C#)中将 html 模板下载为 OFT 文件。我已经尝试过 Microsoft.Office.Interop.Outlook,它在我的本地机器上运行良好,但在服务器上运行失败。它需要在服务器中安装 Outlook,而且我还听说在服务器中为 Web 应用程序自动化 MS Office 应用程序不是一个好习惯。是否可以在不使用 MS Office Outlook 的情况下创建一个经常文件? 有没有免费的图书馆可以做到这一点?任何人都知道解决方案,请帮助。
【问题讨论】:
标签:
c#
asp.net-mvc-4
outlook
oft
【解决方案1】:
OFT 文件是具有不同类 GUID 的 MSG 文件。 MSG 文件是一个 OLE 存储 (IStorage) 文件。
由于 MSG 文件格式为 documented,因此您可以创建一个 CLSID 为 {0006F046-0000-0000-C000-000000000046} 的 MSG 文件,而不是 {00020D0B-0000-0000-C000-000000000046}。
您也可以使用Redemption(我是它的作者)-它的RDO family of objects可以在服务中使用,您只需要确保安装了具有匹配位数的Outlook(兑换使用由安装的MAPI系统) Outlook,而不是 Outlook 对象模型,不能在服务中使用)。
VB 脚本:
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.CreateMessageFromMsgFile("c:\Temp\TestMsg.msg")
Msg.Body = "This is a test template"
Msg.Subject = "Template"
Msg.Save
Msg.SaveAs "c:\Temp\TestTemplate.oft", olTemplate
C#(在我脑海中浮现):
Redemption.RDOSession rSession = new Redemption.RDOSession();
Redemption.RDOMail Msg = rSession.CreateMessageFromMsgFile("c:\Temp\TestMsg.msg");
Msg.Body = "This is a test template";
Msg.Subject = "Template";
Msg.Save();
Msg.SaveAs("c:\Temp\TestTemplate.oft", Redemption.rdoSaveAsType.olTemplate);