Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Outlook template (.oft) file in an ASP.Net MVC application

I've a requirement for downloading an html template as an OFT file in an ASP.Net MVC4 web application (using C#). I've already tried Microsoft.Office.Interop.Outlook, which works perfectly in my local machine but failed to work in the server. It requires Outlook to be installed in the server and I also heard it is not a good practice to automate MS office applications in the server for a web application. Is it possible to create an oft file without using MS Office Outlook? Is there any free libraries for doing this? Anybody knows a solution please help.

like image 508
Arjun Avatar asked Nov 09 '22 21:11

Arjun


1 Answers

OFT file is an MSG file with a different class GUID. MSG file is an OLE Storage (IStorage) file.

Since MSG file format is documented, you can create an MSG file with CLSID of {0006F046-0000-0000-C000-000000000046} instead of {00020D0B-0000-0000-C000-000000000046}.

You can also use Redemption (I am its author) - its RDO family of objects can be used in a service, you just need to make sure that Outlook with the matching bitness is installed (Redemption uses the MAPI system installed by Outlook, not the Outlook Object Model, which cannot be used in a service).

VB script:

  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# (off the top of my head):

  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);
like image 96
Dmitry Streblechenko Avatar answered Nov 14 '22 21:11

Dmitry Streblechenko