0

我有一个 Outlook 插件(将邮件基本推送到我们的应用程序),它在一台机器上返回一个问题(在其他机器上运行良好)。它只是没有错误地工作,所以我们进入 SYSTEM 菜单并打开 VSTO_SUPPRESSDISPLAYALERTS = 0 以推送到屏幕。

然后当我运行同步时,我得到了以下信息

Object reference not set to an instance of an object.


************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at MyAppOutlook.WaitingPopup.btnSyncOutlookInboxMail_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam,     IntPtr lparam)

我无法理解为什么这适用于大多数机器但不适用于这台机器。插件安装并出现在这台机器的工具栏上,就像其他插件一样,它只是不起作用!

在安装我们的插件之前,我已经检查并重新安装了以下内容:

  • .net3.5 框架
  • 2007 年主要互操作程序集

注:展望是 2007 年。

根据要求,该过程的代码如下

Outlook.MAPIFolder outlookSentFolder =     (Outlook.MAPIFolder)outlookObj.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);

for (int i = 1; i <= outlookSentFolder.Items.Count; i++)
{
    Outlook.MailItem mm = outlookSentFolder.Items[i] as Outlook.MailItem;
    if (mm != null)
    {
        try
        {
            DateTime StartDate = new DateTime(((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Year, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Month, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Day, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Hour, ((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.Minute, 0);

            if (StartDate > currentDate) // condition for current month mail sync
            {
                string attachs = "";
                for (int j = 0; j < ((Outlook.MailItem)outlookSentFolder.Items[i]).Attachments.Count; j++)
                {
                    attachs = ((Outlook.MailItem)outlookSentFolder.Items[i]).Attachments[j + 1].FileName.ToString() + "," + attachs;
                }

                ASCIIEncoding encoding = new ASCIIEncoding();
                string postData = "userDBName=" + subsDBName;
                postData += ("|MethodRequestName=addUpdateInboxMailFromOutlookToCRM");
                postData += ("|loginid=" + username);
                postData += ("|MailTo=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).To);
                postData += ("|MailCC=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).CC);
                postData += ("|MailFrom=" + ((Outlook.MailItem)outlookSentFolder.Items[i]).SenderEmailAddress);
                postData += ("|MailSubject=" + ((((((Outlook.MailItem)outlookSentFolder.Items[i]).Subject).Replace("|", "")).Replace("#", "")).Replace("<", "")).Replace(">", ""));
                postData += ("|MailBody=" + ((((((Outlook.MailItem)outlookSentFolder.Items[i]).Body).Replace("|", "")).Replace("#", "")).Replace("<", "")).Replace(">", ""));
                postData += ("|MailSentOn=" + StartDate.ToString("MM/dd/yyyy hh:mm:ss"));//((Outlook.MailItem)outlookSentFolder.Items[i]).SentOn.ToString());
                postData += ("|MailType=Sent");
                postData += ("|MailAttach=" + attachs);
                byte[] data = encoding.GetBytes(postData);

                // Prepare web request...
                HttpWebRequest myRequestSent = (HttpWebRequest)WebRequest.Create(reqURL + "Views/Subscription/OutlookDataService.aspx");
                myRequestSent.Method = "POST";
                myRequestSent.ContentType = "application/x-www-form-urlencoded";
                myRequestSent.ContentLength = data.Length;
                Stream newStream = myRequestSent.GetRequestStream();
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();

                WebResponse responseHtmlSent = myRequestSent.GetResponse();
                string xmlString = "";
                using (StreamReader r = new StreamReader(responseHtmlSent.GetResponseStream()))
                {
                    xmlString = xmlString + r.ReadToEnd();
                }
                responseHtmlSent.Close();
            }
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Warning: " + ex.Message.ToString(), "Warning");
        }
    }
}

请任何人帮忙,因为我们已经设法得到这个错误?但是,我的理解是,这个错误通常意味着我们错误地引用了这些表,但是为什么它会在大多数其他机器上工作呢?

谢谢

4

1 回答 1

0

您是否在处理此问题时将 try...catch 块添加到代码中,还是一直存在?

如果它一直在那里,并且您提到它只是无法正常工作,那么错误必须不在此范围内。我会检查受影响的用户是否确实有一个已发送的邮件文件夹。

于 2011-10-27T12:59:22.483 回答