从Web服务使用Outlook发送电子邮件 [英] Send email using Outlook from web service

查看:86
本文介绍了从Web服务使用Outlook发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP .NET(C#)Web服务应用程序中,我在另一个类(在同一个程序集中)调用方法,如SendEmail()。

我的SendEmail()方法是这样的。

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();





当我在代码电子邮件上运行时,发送成功。然后我发布这个并将其添加到IIS网站。但是当从那里浏览.asmx时出现错误



System.UnauthorizedAccessException:使用CLSID {0006F03A-0000-0000-C000-000000000046}检索组件的COM类工厂由于以下错误而失败:80070005访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))。

在System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)

在System.Runtime.Remoting.Activation。 ActivationServices.CreateInstance(RuntimeType serverType)

在System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType,Object [] props,Boolean bNewObj)

在System。 RuntimeTypeHandle.CreateInstance(RuntimeType类型,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)

at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache)< System.RuntimeType.CreateInstanceDefaultCtor上的
(布尔值publicOnly,布尔值skipVisibilityChecks,布尔值skipCheckThis,布尔值fillCache)

at System.Activator.CreateInstance(Type type,Boolean nonPublic)
S的
ystem.Activator.CreateInstance(Type type)



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)

推荐答案

这是因为在本地计算机上可能安装了Microsoft Outlook并配置了MAPI。

发布时,在您的网络服务器中可能未安装Outlook且无法找到所需的COM组件。



如果您的网络服务器上安装了Outlook ,从您的网络服务器,您无法访问Outlook,因为这将是一个安全违规。您的网络服务将在不同的帐户中运行,无法访问Outlook。
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.


这篇关于从Web服务使用Outlook发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆