您好,我厌倦了试图弄清楚导致此问题的原因,并在没有任何积极结果的情况下对其进行了修复,而我不得不向您寻求帮助。
问题是,以下是我有一个asp.net应用程序,它使用Microsoft.Office.Interop.Outlook发送电子邮件。
当我使用vs iis expres调试应用程序时,它可以正常工作,我的意思是它发送的电子邮件非常好。
我将应用程序发布到服务器上之后,却遇到以下错误:
Server Error in '/' Application.
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)).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: 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)).
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
触发错误的方法如下:
using Outlook = Microsoft.Office.Interop.Outlook;
string rqstornt=BS.BSMaintenance.Instance.GetEmployeeNTUserByID(int.Parse(DdlSwapRequestor.SelectedValue));
string emailRqstor = BS.BSMaintenance.Instance.GetUserEmail(rqstornt);
string providernt= BS.BSMaintenance.Instance.GetEmployeeNTUserByID(int.Parse(DdlSwapProvider.SelectedValue));
string emailProvider = BS.BSMaintenance.Instance.GetUserEmail(providernt);
string requestor=DdlSwapRequestor.SelectedItem.Text;
string provider = DdlSwapProvider.SelectedItem.Text;
string startdate = DpStartDate.Text;
string enddate = DpEndDate.Text;
if (!string.IsNullOrEmpty(emailRqstor)&(!string.IsNullOrEmpty(emailProvider)))
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mail.Subject = "Swap Request Date: "+DateTime.Now.ToString();
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
string swrequestor= HttpUtility.UrlEncode(Encrypt(requestor));
string swprovider = HttpUtility.UrlEncode(Encrypt(provider));
string swstdt = HttpUtility.UrlEncode(Encrypt(startdate));
string swedt = HttpUtility.UrlEncode(Encrypt(enddate));
mail.HTMLBody = "<h1>Hi</h1><br/>The employe: " + requestor + " is requesting schedule swap with " + provider + " from " + startdate + " to " + enddate + "<br/> If you accept the schedule swap please go to the link below in order to approve the swap.<br/><br/>" +
"Click the link to approve/reject it: "+ string.Format("http://g7w00634a.inc.hpicorp.net:60787/Presentation/WebPages/SwapsModule.aspx?rqst={0}&prvd={1}&swstd={2}&swed={3}", swrequestor, swprovider, swstdt, swedt);
mail.Save();
//mail.To = "lucian.smith.ulloa@hp.com;cesar.carranza.quesada1@hp.com;carlos.gamboa@hp.com;";
mail.To = "catalina.isa.blanco-montero@hp.com;lorna.rod.murillo@hp.com";
mail.CC = emailRqstor+";"+emailProvider+";cesar.carranza.quesada1@hp.com";
mail.Send();
PnlError.Visible = false;
PnlSucess.Visible = true;
LbMsjSucess.Text = "You have sucessfully requested the a scheduled swap. ";
希望我提供的代码和错误足够了,以便您了解导致此问题的原因并可以帮助我解决该问题。
预先感谢您的帮助。