SecurityManager.2005 for Office 2007 error: Value does not fall within the expected range

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

SecurityManager.2005 for Office 2007 error: Value does not fall within the expected range
getting an error at this line sManager.connectTo(OutlookApp) when trying to send an email from web service 
cgunturu@sjm.com gunturu




Posts: 4
Joined: 2011-01-12
Hi,I am trying to send an email out from a web service using outlook,here is the line of code(sManager.ConnectTo(oApp))
that is giving an error from the code below.Can you please help me out with this issue.
I am able to send email out from windows application but not from a web service.


[/CODE]
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

oNS.Logon("Outlook", Missing.Value, false, false);
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); SecurityManager sManager = new SecurityManager();

//sManager.ConnectTo(oApp)
sManager.DisableOOMWarnings = true;


Thanks,
Posted 13 Jan, 2011 18:13:28 Top
Renat Tlebaldziyeu


Guest


Hi Chandra,

Please try this code, i have just tested it on my PC from a web service and it works without any problems:

AddinExpress.Outlook.SecurityManager securityManager1 = new AddinExpress.Outlook.SecurityManager();
Outlook.Application outlookApp = null;
Outlook.NameSpace outlookNamespace = null;
Outlook.MailItem oMsg = null;
try
{
	outlookApp = new Outlook.Application();
	if (outlookApp != null)
	{   
		outlookNamespace = outlookApp.GetNamespace("MAPI");
		if (outlookNamespace != null)
		{
			outlookNamespace.Logon("Outlook", Missing.Value, true, true);
			securityManager1.ConnectTo(outlookApp);
			securityManager1.DisableOOMWarnings = true;
			try
			{
				oMsg = outlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
				if (oMsg != null)
				{
					//...
				}                                
			}
			finally
			{
				securityManager1.DisableOOMWarnings = false;
				securityManager1.Disconnect(outlookApp);
			}
			outlookNamespace.Logoff();
		}
	}                
}
finally
{
	if (outlookApp != null)
	{
		Marshal.ReleaseComObject(outlookApp);
		outlookApp = null;
	}
	if (outlookNamespace != null)
	{
		Marshal.ReleaseComObject(outlookNamespace);
		outlookNamespace = null;
	}
	if (oMsg != null)
	{
		Marshal.ReleaseComObject(oMsg);
		oMsg = null;
	}
}
Posted 14 Jan, 2011 05:17:52 Top
cgunturu@sjm.com gunturu




Posts: 4
Joined: 2011-01-12
Hi Renat,
I am able to execute this code with out any issues from windows application but when i use this in a web service i get this error

//Exception
System.ArgumentException: Value does not fall within the expected range.
at AddinExpress.Outlook.IOutlookSecurityManager2.Connect(Object vTarget)
at AddinExpress.Outlook.SecurityManager.ConnectTo(Object outlookApp).
//

I emailed you the code, can you please help me out with this issue.

Thanks,
Chandra
Posted 14 Jan, 2011 12:09:33 Top
Renat Tlebaldziyeu


Guest


Hi Chandra,

Do you have secman.dll registered on the PC?
If it?Â?Ð?és not registered try to register it manually from the command line:

regsvr32 "C:\Program Files\Common Files\Outlook Security Manager\secman.dll"

Did it help?
Posted 14 Jan, 2011 12:29:08 Top
cgunturu@sjm.com gunturu




Posts: 4
Joined: 2011-01-12
Hi,
I successfully registered the dll and executed the code, still getting the same error.
It did not help.

Error:

System.ArgumentException: Value does not fall within the expected range.
at AddinExpress.Outlook.IOutlookSecurityManager2.Connect(Object vTarget)
at AddinExpress.Outlook.SecurityManager.ConnectTo(Object outlookApp)
Thanks,
Posted 14 Jan, 2011 14:01:56 Top
Renat Tlebaldziyeu


Guest


Hi Chandra,

I think the problem is that the Web service works as multi-threaded (MTA) application.
I created a test project for you and have sent it by email. Please check your inbox.
It uses a STA background thread for calling the Security Manager methods.
Please test it on your PC and let me know about the results.
Posted 17 Jan, 2011 04:34:16 Top
cgunturu@sjm.com gunturu




Posts: 4
Joined: 2011-01-12
The problem is resolved partially with the solution you suggested above.If I execute the web service with the web properties to use the Visual Studio development server instead of publishing the web service as a virtual directory it is working fine.But If I create a virtual directory, it is failing at this last line of code below when Activator returns an instance of Outlook application object.I get a COM Exception[E INVALID] and the web service is hanging up and timing out.
[CODE]
public void SendMailThreaded()
{
AddinExpress.Outlook.SecurityManager securityManager1 = new AddinExpress.Outlook.SecurityManager();
Outlook.Application outlookApp = null;
Outlook.NameSpace outlookNamespace = null;
Outlook.MailItem oMsg = null;
try
{
Type OutlookType = Type.GetTypeFromProgID("Outlook.Application");
outlookApp = Activator.CreateInstance(OutlookType) as Outlook.Application;
can you please check if you also get the same error.

Thanks,
Chandra
Posted 18 Jan, 2011 01:08:17 Top
Renat Tlebaldziyeu


Guest


Hi Chandra,

I found the article for you:
http://support.microsoft.com/kb/257757
In this article Microsoft states:
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 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.


Also I found that this is probably related to the DCOM security configuration. The following article is about Excel, but the same settings probably apply to Outlook as well: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx
You can try to modify those settings on your web server.
Posted 18 Jan, 2011 06:38:12 Top