我通过这个C#代码从outlook获取未读的电子邮件。但现在我想找到所有阅读和邮件,这些阅读和邮件已经给出了来自outlook的电子邮件,并使用C#代码删除了它们。 [英] I'm getting the unread emails from outlook through this C# code. But now I want to find all read and mails that had given repliyes to the emails from outlook and delete them using C# code.
本文介绍了我通过这个C#代码从outlook获取未读的电子邮件。但现在我想找到所有阅读和邮件,这些阅读和邮件已经给出了来自outlook的电子邮件,并使用C#代码删除了它们。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
// login
mapiNameSpace.Logon( null , null , false ,假跨度>);
mapiNameSpace.Logon( yourMailAddress, password,Missing.Value, true );
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
// Console.WriteLine(Total:,myItems.Count);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
// Console.Write(myInbox.Name);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
// Console.WriteLine(Total:,inboxItems.Count);
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer( false );
mapiNameSpace.Logon( Profile,Missing.Value, false , true );
if (myInbox.Items.Count > 0 )
{
Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
inboxItems = inboxItems.Restrict( [UnRead] = true);
Console.WriteLine( string .Format( 未读消息总数{0}:,inboxItems.Count));
int x = 0 ;
foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
{
Console.WriteLine( {0}来自收件箱的未读邮件,+ + X);
Console.WriteLine( string .Format( from: - {0},item.SenderName));
Console.WriteLine( string .Format( 收件人: - {0},item.ReceivedByName));
Console.WriteLine( string .Format( 主题: - {0},item.Subject));
Console.WriteLine( string .Format( 消息: - {0},item.Body));
System.Threading.Thread.Sleep( 1000 );
}
Console.ReadKey();
解决方案
我' m使用此方法,但我需要它一直运行,我使用 while()而不是 if(myInbox.Items.Count> 0),所以,当循环 使用 21 次会引发错误。
未受控制System.Runtime.InteropServices.COMException
消息=由于注册表问题或安装,操作失败。重新启动Outlook并再次尝试。如果问题仍然存在,请重新安装。
Source = Microsoft Outlook
ErrorCode = -2147221225
StackTrace:
Microsoft.Office.Interop.Outlook.ItemsClass .Restrict( String 过滤器)
LeerCorreos.Program.Main( String [] args)zh C:\ Users \Usuario \documents\visual studio 2010 \Projects \LeerCorreos \ LeerCorreos \Program.cs:línea 46
System.AppDomain._nExecuteAssembly(Assembly assembly , String [] args)
in System.AppDomain.ExecuteAssembly( String assemblyFile,Evidence assemblySecurity, String [] args)
in Microsof t.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context( Object state)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()
InnerException:
哪里抛出错误 此行:
inboxItems = inboxItems.Restrict( [UnRead] = true);
你能帮帮忙吗?我真的很感激,我不知道' 知道如何解决它跨度>
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 myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
//login
mapiNameSpace.Logon(null, null, false, false);
mapiNameSpace.Logon("yourMailAddress", "password", Missing.Value, true);
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
// Console.WriteLine("Total : ", myItems.Count);
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
// Console.Write(myInbox.Name);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
// Console.WriteLine("Total : ", inboxItems.Count);
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer(false);
mapiNameSpace.Logon("Profile", Missing.Value, false, true);
if (myInbox.Items.Count > 0)
{
Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
inboxItems = inboxItems.Restrict("[UnRead] = true");
Console.WriteLine(string.Format("Total Unread message {0}:", inboxItems.Count));
int x=0;
foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
{
Console.WriteLine("{0} unread mail from your inbox", ++x);
Console.WriteLine(string.Format("from:- {0}", item.SenderName));
Console.WriteLine(string.Format("To:- {0}", item.ReceivedByName));
Console.WriteLine(string.Format("Subject:- {0}", item.Subject));
Console.WriteLine(string.Format("Message:- {0}", item.Body));
System.Threading.Thread.Sleep(1000);
}
Console.ReadKey();
解决方案
Hi, I'm using this method, but I need it's runs all the time, I use a "while()" instead of "if(myInbox.Items.Count > 0)", so, when the cycle is used 21 times throws me an error. Was not controlled System.Runtime.InteropServices.COMException Message=The operation failed due to a registry problem or installation. Restart Outlook and try again. If the problem persists, reinstall it. Source=Microsoft Outlook ErrorCode=-2147221225 StackTrace: in Microsoft.Office.Interop.Outlook.ItemsClass.Restrict(String Filter) in LeerCorreos.Program.Main(String[] args) en C:\Users\Usuario\documents\visual studio 2010\Projects\LeerCorreos\LeerCorreos\Program.cs:línea 46 in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() in System.Threading.ThreadHelper.ThreadStart_Context(Object state) in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Threading.ThreadHelper.ThreadStart() InnerException: Where throws the error is in this line: inboxItems = inboxItems.Restrict("[UnRead] = true"); can you help?, I really appreciate it, I don't know how to resolve it
这篇关于我通过这个C#代码从outlook获取未读的电子邮件。但现在我想找到所有阅读和邮件,这些阅读和邮件已经给出了来自outlook的电子邮件,并使用C#代码删除了它们。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文