无法从c#code :: Getting Unspecified error(从HRESULT异常:0x80004004(E_Abort))读取Sender Infromation [英] Not able to read Sender Infromation from c# code :: Getting Unspecified error (Exception from HRESULT: 0x80004004 (E_Abort))

查看:131
本文介绍了无法从c#code :: Getting Unspecified error(从HRESULT异常:0x80004004(E_Abort))读取Sender Infromation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我的目的是阅读Outlook邮件项目中的发件人姓名,电子邮件地址等基本信息,以便我创建一个控制台应用程序。打破我用过的基本代码。

My aim is to read basic information like sender Name, email address from outlook mail item for that I created one console application. Blow basic code I used for that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Outlook;

namespace MAPI
{
    class Program
    {
        static void Main(string[] args)
        {


            string lblSubject, txtBody, lblSenderName, lblSenderEmail;
             List<string> litems = new List<string>();

            try
            {
                Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
                Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
                Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                if (myInbox.Items.Count > 0)
                {
                    
                    lblSubject = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Subject;
                    

                    litems.Add(lblSubject);

                    txtBody = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).Body;
                    litems.Add(txtBody);

                    lblSenderName = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).SenderName;
                    litems.Add(lblSenderName);

                    lblSenderEmail = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).SenderEmailAddress;
                    litems.Add(lblSenderEmail);


                    Console.WriteLine(lblSubject +  "," + txtBody + "," + lblSenderName + "," + lblSenderEmail);

                }
                else
                {
                    Console.WriteLine("There are no emails in your Inbox.");
                }
            }
            catch (System.Exception ex)
            {
                foreach(string item in litems)
                {
                    Console.Write(item);
                }

                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadLine();
            }

        }
    }
}

以上代码目标版本是x86机器。

Above code target build is x86 machines.

我无法从我的代码中读取我所期望的信息,在少数机器中获取outlook 2010中的错误。

I'm not able to read the information what I'm expected from my code, getting error in outlook 2010 in few machines.

未指定错误(HRESULT异常:0x80004005(E_FAIL))

并且在少数机器中

未指定错误(操作从HRESULT中止:0x80004004(E_Abort))

我希望我的代码是完美的,因为我可以从不同的交换服务器获取相同的信息以及不同的Outlook版本说2013 2016年,使用相同的代码。

系统规格在哪里我收到错误:

System specifications where I'm getting error:

Outlook 2010

Outlook 2010

Windows 7 64位

Windows 7 64 bit

McAfee端点保护(它的保护前景电子邮件 我认为 - 不是有权在此处更改设置)

McAfee End point protection (its protecting outlook emails also I think - not having permissions to change settings here )

某些组策略应用于同一台计算机上

Some group policies are applied on same machine

我在我的计算机上拥有完整权限(管理员)

And I'm having complete rights(Admin) on my machine

请帮助哪一个阻止我获取这些详细信息或任何代码  需要更改 

Can you please help which one blocking me to get those details or any code  changes needed ??

或者Outlook 2010 客户端中的任何设置都需要更改?或McAfee有任何特殊设置来阻止阅读Outlook邮件
以编程方式 ??或者是否有机会使用组策略阻止对Outlook项目进行程序性读取?

Or any settings in outlook 2010 client need to be changed?? or McAfee having any special setting to block reading of outlook mails programmatically?? or Is there any chance to block programatic reading of outlook items using group policy??

交换服务器级别是否存在阻止我的任何权限? (Exchange sever 2003 - 补丁适用于支持2010)

Is there any permissions at exchange server level which blocking me?? (exchange sever 2003 - patch applied to support 2010)

请帮我解决这个问题。 您的帮助应该是非常有用的。

Please Help me out from this issue. YOUR HELP SHOULD BE MUCH APPRICIATED.

您可以随意提出所需的任何其他信息来解决此问题。

Feel free to ask any other information needed for you to sortout this issue.

谢谢,

Adithya。

推荐答案

您好Adithya,

Hello Adithya,

首先,我注意到以下代码行,您可以将文件夹中的每个对象发送到MailItem类:

First of all, I have  noticed the following line of code where you can each object in the folder to the MailItem class:

lblSenderEmail = ((Microsoft.Office.Interop.Outlook.MailItem)myInbox.Items[1]).SenderEmailAddress;

请记住,文件夹可能包含各种类型的项目。您需要先检查类型。看看下面的示例代码:

Please remember that folders may contain various types of items. You need to check the type first. Take a look at the following sample code:

if (this.Application.ActiveExplorer().Selection.Count > 0)
        {
            Object selObject = this.Application.ActiveExplorer().Selection[1];
            if (selObject is Outlook.MailItem)
            {
                Outlook.MailItem mailItem =
                    (selObject as Outlook.MailItem);
                itemMessage = "The item is an e-mail message." +
                    " The subject is " + mailItem.Subject + ".";
                mailItem.Display(false);
            }
            else if (selObject is Outlook.ContactItem)
            {
                Outlook.ContactItem contactItem =
                    (selObject as Outlook.ContactItem);
                itemMessage = "The item is a contact." +
                    " The full name is " + contactItem.Subject + ".";
                contactItem.Display(false);
            }
            else if (selObject is Outlook.AppointmentItem)
            {
                Outlook.AppointmentItem apptItem =
                    (selObject as Outlook.AppointmentItem);
                itemMessage = "The item is an appointment." +
                    " The subject is " + apptItem.Subject + ".";
            }
            else if (selObject is Outlook.TaskItem)
            {
                Outlook.TaskItem taskItem =
                    (selObject as Outlook.TaskItem);
                itemMessage = "The item is a task. The body is "
                    + taskItem.Body + ".";
            }
            else if (selObject is Outlook.MeetingItem)
            {
                Outlook.MeetingItem meetingItem =
                    (selObject as Outlook.MeetingItem);
                itemMessage = "The item is a meeting item. " +
                     "The subject is " + meetingItem.Subject + ".";
            }

在以下文章中了解更多相关信息:

Read more about that in the following articles:

如何:以编程方式确定当前的Outlook项目

如何从Visual
Basic中获取Outlook文件夹中当前选定的项目

您很可能面临标准的Outlook安全问题。 ""Security"在这种情况下,所谓的"对象模型防护"是指所谓的"对象模型防护"。这会触发安全提示并阻止对某些功能的访问,以防止
恶意程序从Outlook数据中收集电子邮件地址并使用Outlook传播病毒和垃圾邮件。除了在Outlook 2007及更高版本中运行防病毒应用程序之外,不能简单地关闭这些提示。您可以在  展望中了解可能的
方式来抑制或避免此类问题"对象模型保护"开发人员的安全问题
 文章。 

Most probably you faced with a standard Outlook security issue. "Security" in this context refers to the so-called "object model guard" that triggers security prompts and blocks access to certain features in an effort to prevent malicious programs from harvesting email addresses from Outlook data and using Outlook to propagate viruses and spam. These prompts cannot simply be turned off, except in Outlook 2007 and later with an anti-virus application running. You can read about possible ways for suppressing or avoiding such issues in the Outlook "Object Model Guard" Security Issues for Developers article. 

最多常见的方法是:

1。使用扩展MAPI(或该API周围的任何其他第三方包装)而不是OOM。

< span style ="font-size:11px"> 2。使用 Outlook Security Manager 组件。 

2. Use the Outlook Security Manager component. 

3。 T 管理员可以选择放宽部分或全部的Outlook安全性用户通过GPO。


这篇关于无法从c#code :: Getting Unspecified error(从HRESULT异常:0x80004004(E_Abort))读取Sender Infromation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆