1

We have a vb.net windows application that creates an instance of Outlook.Application to open an email .MSG file, and save it as a .HTML by calling the Outlook.Application SaveAs() method.

However, sometimes the call to .SaveAs() causes a popup to appear, for example when saving a .MSG that is digitally signed, there is a confirmation popup.

This popup causes the code execution to halt until the user interacts and clicks YES or NO on the pop up. Since our application runs on a server and requires no user interaction this causes the application to halt periodically until a technician logs into the server and clicks 'yes' on the popup.

Is there a way to avoid this pop up, or have 'YES' automatically get selected? I've tried investigating the documentation for Outlook.Application but of course the documentation is very lacking on MSDN.

Here is some example vb.net code:

outlookapp = CreateObject("Outlook.Application")
Dim olItem As Object = outlookapp.CreateItemFromTemplate("C:\msg\message.msg")
olItem.SaveAs("C:\html\convertedmessage.html", 5)

If message.msg is digitally signed, when calling SaveAs() to save it as an HTML file, you get a pop up that the MSG is digitally signed, this halts the code until you click yes or no.

Note: Outlook objects do not support the DisplayAlerts flag of Word objects.

evolvedant
  • 13
  • 3
  • Possible duplicate of [How to disable popups when openning in office-interop](http://stackoverflow.com/questions/5575117/how-to-disable-popups-when-openning-in-office-interop) – T.S. Nov 03 '16 at 20:16
  • Not a duplicate since that post is about Word which supports setting 'DisplayAlerts' to false. This question is for Outlook, which does not have this method. – evolvedant Nov 03 '16 at 20:48
  • I think, it is all same for all office apps - `Application.DisplayAlerts = False` – T.S. Nov 03 '16 at 20:53
  • No, there is no Application.DisplayAlerts for Outlook. – Dmitry Streblechenko Nov 03 '16 at 21:10

1 Answers1

0

Firstly, Outlook is not designed to be used in a service or a server side application with no user present.

In your particular case, you can do the following:

1 Use Extended MAPI (C++ or Delphi only) to open the MSG file (OpenIMsgOnIStg etc.), then construct the HTML file explicitly in your code.

2 Parse the MSG file (its format is documented) or use one of several commercial components (such as the one from Aspose) to read the MSG files.

3 Use Redemption (I am its author) and its RDOSession.GetMessageFromMsgFile / RDOMail.SaveAs(..., olHTML) methods to open the MSG file and perform the conversion.

dim Session As RDOSession = CreateObject("Redemption.RDOSession")
dim Msg As RDOMail = Session.GetMessageFromMsgFile("C:\msg\message.msg")
Msg.SaveAs("C:\html\convertedmessage.html", 5)
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78