代码之家  ›  专栏  ›  技术社区  ›  Some_Dude

从服务器创建新的Outlook电子邮件时出错

c#
  •  0
  • Some_Dude  · 技术社区  · 6 年前

    我有一个功能,可以在outlook中创建一个新的电子邮件,在我的本地计算机上运行时工作正常。但是,当部署到服务器时,我得到如下所示的错误。

    这就是我在本地计算机上运行代码时的情况: Link 是的。是否可以使此代码在服务器上运行并为用户生成电子邮件?

    错误:

    system.runtime.interopservices.com exception(0x80080005):检索CLSID为{0006f03a-0000-0000-c000-0000000000 46}的组件的COM类工厂失败,原因是以下错误:80080080005服务器执行失败(来自hresult的异常:0x80080005(co-e-u-server-exec-u failure))。在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 type,boolean publiconly,boolean nocheck,boolean&canbecached,runtimemethodhandleinternal&ctor,boolean&bneedsecuritycheck)位于system.runtimetype.createinstanceslow(boolean publiconly,boolean skipcheckthis,boolean fillcache,stackcrwlmark&stackmark)system.activator.createInstanceDefaultctor(boolean publicOnly,boolean skipcheckthis,boolean fillcache,stackcrawlmark&stackmark)位于system.activator.createInstance(type type,boolean non public)位于system.activator.createInstance(type)位于myprojectname.btnemailestimate\u click(object sender,事件参数e)位于d:\ my\project\location\myprojectname.ascx.cs:line 9833

    这是我的代码:

        protected void btnEmailEstimate_Click(object sender, EventArgs e)
        {
            try
            {
                List<string> lstAllRecipients = new List<string>();
                //Below is hardcoded - can be replaced with db data
                lstAllRecipients.Add("test1@testmail.com");
                lstAllRecipients.Add("test2@testmail.com");
    
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector oInspector = oMailItem.GetInspector;
    
                // Recipient
                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
                foreach (String recipient in lstAllRecipients)
                {
                    Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
                    oRecip.Resolve();
                }
    
                //Add CC
                Outlook.Recipient oCCRecip = oRecips.Add("testCC@testmail.com");
                oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
                oCCRecip.Resolve();
    
                //Add Subject
                oMailItem.Subject = "Test Mail";
    
                // body, bcc etc...
                oMailItem.Body = "Email body content here \nThis is a new line.";
    
                //Display the mailbox
                oMailItem.Display(true);
                var time = DateTime.Now;
                tbLast_email_update.Text = time.ToString();
            }
            catch (Exception objEx)
            {
                Response.Write(objEx.ToString());
            }
        }
    
    0 回复  |  直到 6 年前