Send Email from web service

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
In my ASP .NET (C#) web service application Im calling method in another class (in same assembly) like SendEmail().<br/>
My SendEmail() method is like this.<br/>
<br/>
Outlook.Application oApp;<br/>
Outlook._NameSpace oNameSpace;<br/>
Outlook.MAPIFolder oOutboxFolder;<br/>
<br/>
oApp = new Outlook.Application();<br/>
<br/>
oNameSpace = oApp.GetNamespace("MAPI");<br/>
oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);<br/>
<br/>
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);<br/>
oMailItem.To = "sanjeewa@ss.com";<br/>
oMailItem.Subject = "subjectValue";<br/>
oMailItem.Body = "bodyValue";<br/>
oMailItem.SaveSentMessageFolder = oOutboxFolder;<br/>
<br/>
oMailItem.Send();<br/>
<br/>
<br/>
When Im 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<br/>
<br/>
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)).<br/>
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)<br/>
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)<br/>
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)<br/>
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)<br/>
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)<br/>
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)<br/>
at System.Activator.CreateInstance(Type type, Boolean nonPublic)<br/>
at System.Activator.CreateInstance(Type type)

View the full article
 
Back
Top