Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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)
Posted 17-Dec-12 21:47pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
sanjeewabdissa at 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 at 18-Dec-12 23:14pm
   
I am not clear on your complete requirement. Any specific why do you want to send emails using Outlook?
sanjeewabdissa at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100