In my ASP .NET (C#) web service application I'm calling method in another class (in same assembly) like SendEmail().
My SendEmail() method is like this.
Outlook.Application oApp;
Outlook._NameSpace oNameSpace;
Outlook.MAPIFolder oOutboxFolder;
oApp = new Outlook.Application();
oNameSpace = oApp.GetNamespace("MAPI");
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "sanjeewa@ss.com";
oMailItem.Subject = "subjectValue";
oMailItem.Body = "bodyValue";
oMailItem.SaveSentMessageFolder = oOutboxFolder;
oMailItem.Send();
When I'm running this on code email is sending successfully. Then I publish this and added this to the IIS web sites. But when browsing the .asmx from there error comes
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)