outlook仅限于此计算机如何解决,以编程方式生成Outlook电子邮件

I am creating a button in asp.net c# that when clicked will open up Outlook window.

I am referencing to the Microsoft.Office.Interop.Outlook dll, and using this in using statement:

using Outlook = Microsoft.Office.Interop.Outlook;

This the code.

private void CreateMailItem()

{

try

{

var outlookApp = new Outlook.Application();

var mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

//var mailItem = (Outlook.MailItem)

// Application.CreateItem(Outlook.OlItemType.olMailItem);

mailItem.Subject = "This is the subject";

mailItem.To = "someone@example.com";

mailItem.Body = "This is the message.";

mailItem.Importance = Outlook.OlImportance.olImportanceLow;

mailItem.Display(false);

}

catch (Exception)

{

throw;

}

}

I get error on the very first line, var outlookApp = new Outlook.Application();

The exception says:

{"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))."}

Talk1:

What does exception say?

Talk2:

Sorry. Forgot to add the exception. Will edit the text. It says: {"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))."}

Talk3:

Similar office issue here. Are you trying to send the email from the server or the client? If it's from the server you might be better off doing this over SMTP.

Talk4:

I need to send it from the client, but right now I am testing on my development server where I have installed Outlook (2010)

Solutions1

The exception you've posted is thrown when a referenced dll or depencies of this dll are not correctly installed.

In this case, it seems outlook or office is not with the correct version which you referenced, on your test machine?

Talk1:

I am testing on Outlook 2010, and have tried both version 14 and 15 of the dll Microsoft.Office.Interop.Outlook

Solutions2

Can't post this as comment.

I would like to know why you prefer the use of Outlook Interop?

I am using the mailto:// protocol if I wanted my program to send email on the user's current email client, though I use this on WinForms.

Talk1:

Because I don't know better :). i am new to this, so it just kind of sounded naturally to use Outlook.Interop. Mailto looks good. Can it take attachments ?

Talk2:

Nope. I only include the path of the file to be attached. This could work if you have a dedicated file server.

Solutions3

Outlook, just like any Office app, cannot be used from a service (such as IIS). Even if you did make it work, the new message window will be displayed on the server where the user will not see it anyway.

You can try to run a client-side JavaScritp code, but then you'd be limited IE only, Outlook would need to be locally installed, and your site must be trusted to be able to create COM objects in a script.

Solutions4

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

Consider using System.Net.Mail namespace for creating and sending emails in ASP.NET.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值