Outllok Security Manager returns HRESULT E_FAIL

Add-in Express™ Support Service
That's what is more important than anything else

Outllok Security Manager returns HRESULT E_FAIL
 
Mike Stancliff




Posts: 3
Joined: 2009-12-22
I'm using Outlook Security manager to avoid the security popups when programmatically sending email through Oulook 2003. This app is running unattended on a virtual machine. The application is installed through ClickOnce, and I'm using Reg-free COM to handle installing secman.dll. I've double checked, and the Isolated property ifor the reference to secmanLib is set to True.

After installing the app, it will send the first few emails with no problem, and then begin to throw HRESULT E_FAIL errors. It will continue to throw these errors until I reinstall the app.

This may be too much of an information dump, but here is the code and the error message Any help or suggestion would be grreatly appreciated.

The code:

public static void SendMessage(List<string> recipients, string subject, string body, List<string> attachments)
{
// Create the application and mailItem objects
Application outlook = new Application();
SecurityManager securityManager = new SecurityManager();

try
{
// disable security warnings
securityManager.ConnectTo(outlook);
securityManager.DisableOOMWarnings = true;

MailItem message = (MailItem) outlook.CreateItem(OlItemType.olMailItem);

[... build the mail mesage ... ]

message.Send();
}
catch (System.Exception ex)
{
// rethrow the exception to be caught in the calling code
throw new System.Exception(ex.Message);
}
finally
{
// clean up - enable security warnings
securityManager.DisableOOMWarnings = false;
securityManager.Disconnect(outlook);
}
}


And this is the error that is being reported:

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at AddinExpress.Outlook.IOutlookSecurityManager2.Check(Int32 apiType)
at AddinExpress.Outlook.SecurityManager.set_DisableOOMWarnings(Boolean value)
at PlusOpsFunctions.EmailImporter.SendFromOutlook(String to, String subject, String body, _MailItem origMail)
at PlusOpsFunctions.EmailImporter.SendErrorEmail(String subject, String body, _MailItem oldMail)
at PlusOpsFunctions.EmailImporter.ReadEmail()
at PlusOpsEmail.FrmPlusOpsEmail.StartEmailImporter(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3603 (GDR.050727-3600)
CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
PlusOpsEmail
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Apps/2.0/LOVC7WRN.HPD/X6WDHO72.Q9D/plus..tion_9cc9e8ae4bc8dd07_0001.0001_87352baa932d1337/PlusOpsEmail.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PlusOpsFunctions
Assembly Version: 1.0.0.1
Win32 Version: 1.0.0.1
CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Apps/2.0/LOVC7WRN.HPD/X6WDHO72.Q9D/plus..tion_9cc9e8ae4bc8dd07_0001.0001_87352baa932d1337/PlusOpsFunctions.DLL
----------------------------------------
System.Data.SqlServerCe
Assembly Version: 9.0.242.0
Win32 Version: 3.0.5300.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Data.SqlServerCe/9.0.242.0__89845dcd8080cc91/System.Data.SqlServerCe.dll
----------------------------------------
Microsoft.Office.Interop.Outlook
Assembly Version: 12.0.0.0
Win32 Version: 12.0.4518.1014
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Outlook/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Outlook.dll
----------------------------------------
SecurityManager.2005
Assembly Version: 5.0.2013.2005
Win32 Version: 5.0.2013.2005
CodeBase: file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Apps/2.0/LOVC7WRN.HPD/X6WDHO72.Q9D/plus..tion_9cc9e8ae4bc8dd07_0001.0001_87352baa932d1337/SecurityManager.2005.DLL
----------------------------------------
Posted 22 Dec, 2009 20:00:35 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Mike,

Thank you for providing all the info.

You need to comment out the following line:
securityManager.Disconnect(outlook);


Andrei Smolin
Add-in Express Team Leader
Posted 23 Dec, 2009 05:46:17 Top
Mike Stancliff




Posts: 3
Joined: 2009-12-22
Andrei -

Thanks for the suggestion. I commented out the Disconnect() line and tested it again. The app still sends 1-3 (usually 2) emails, and then I receive the exact same HRESULT E_FAIL error that I copied into the original message. At that point the app freezes and has to be restarted.

Do you have any other ideas? I'm really struggling with this.

Thanks-
Mike
Posted 23 Dec, 2009 13:38:53 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Mike,

I can't see that you close Outlook when the procedure finishes. Can this be the cause of the issue?


Andrei Smolin
Add-in Express Team Leader
Posted 24 Dec, 2009 02:47:47 Top
Mike Stancliff




Posts: 3
Joined: 2009-12-22
Andrei -

Thanks for the help. Your suggestions helped me find that there was another Interop.Outlook.Application object in the class. Once I rewrote the code to get rid of one of them, the app works like it should. I'm guessing that changing the security settings in one of the objects (but not the other) caused a conflict that caused the HRESULT E_FAIL error. In any case, it seems to work now.

Thanks again for the help.

Mike
Posted 24 Dec, 2009 11:42:50 Top
Dennis Chee




Posts: 1
Joined: 2009-12-30
Hi Mike,

Would you mind to share me your detail on how to apply Reg-free COM for secman.dll. How do you create the manifest?

Microsoft Visual Studio 2008
Outlook Security Manager 2009
ClickOnce Deployment

Regards,
Dennis
Posted 30 Dec, 2009 16:31:12 Top
Eugene Astafiev


Guest


Hello Dennis,

Please have a look at the following http://msdn.microsoft.com/en-us/magazine/cc188708.aspx.
Posted 05 Jan, 2010 06:13:59 Top