Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
C#
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)
Posted

1 solution

This is because on your local machine you might have Microsoft Outlook installed and MAPI is configured.
When you publish, in your webserver may be Outlook is not installed and it is not able to find the required COM component.

If Outlook is installed on your webserver, from your webserver you cannot access outlook as that will be a security violation. Your webservice will be running in different account and cannot access Outlook.
 
Share this answer
 
Comments
Sanyon_d 18-Dec-12 22:40pm    
Thanks for the reply. Then how can I send email from the web service using Outlook. Outlook is installed in the web server.
Kiran Susarla 18-Dec-12 23:14pm    
I am not clear on your complete requirement. Any specific why do you want to send emails using Outlook?
Sanyon_d 20-Dec-12 23:36pm    
Because server has configured the outlook only.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900