通过Outlook发送电子邮件不在IIS上工作

时间:2014-04-07 16:01:06

标签: c# iis outlook

在调试中运行时,我的代码运行正常并通过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

1 个答案:

答案 0 :(得分:1)

没有Office应用程序(包括Outlook)可以在服务(例如IIS)中运行。 您的选项是扩展MAPI(仅限C ++或Delphi),Redemption(包装扩展MAPI,可以从任何语言访问,包括C#),EWS(仅限Exchange)或直接SMTP。