C# 通过Outlook发送电子邮件在IIS上不起作用

C# 通过Outlook发送电子邮件在IIS上不起作用,c#,iis,outlook,C#,Iis,Outlook,在debug中运行时,我的代码运行良好,可以通过Outlook发送电子邮件,但是当我将其放到IIS(同一台机器和开发人员)上时,电子邮件不会通过。你知道为什么吗 当前代码 try { //creates outlook app Outlook.Application oApp; //checks to see if outlook is already running, if

在debug中运行时,我的代码运行良好,可以通过Outlook发送电子邮件,但是当我将其放到IIS(同一台机器和开发人员)上时,电子邮件不会通过。你知道为什么吗

当前代码

try
            {
                //creates outlook app
                Outlook.Application oApp;

                //checks to see if outlook is already running, if not create a new instance of it
                try { 
                    oApp = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application"); 
                }
                catch (Exception ex) {
                    oApp = new Outlook.Application();
                }


                // Create a new mail item.
                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                // Set HTMLBody. 
                //add the body of the email
                oMsg.HTMLBody = "This is an email to notify you that there is a new Experimental MEO added";

                //Subject line
                oMsg.Subject = "NEW MEO EXPERIMENTAL ADDED.";

                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                // Change the recipient in the next line if necessary.
                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email@address.com");
                oRecip.Resolve();

                // Send.
                ((Outlook._MailItem)oMsg).Send();


                // Clean up.
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oMsg);
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecip);
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oRecips);
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp);
            }//end of try block
    catch (Exception ex)
       {
       }//end of catch
任何Office应用程序(包括Outlook)都不能在服务(如IIS)中运行。 您的选项是扩展MAPI(仅限C++或Delphi),(它包装扩展MAPI,可以从任何语言(包括C#)、EWS(仅限Exchange)或直接SMTP)访问