gpt4 book ai didi

c# - 在 C# 中访问 Outlook 2010 邮件文件夹

转载 作者:太空狗 更新时间:2023-10-29 23:47:21 26 4
gpt4 key购买 nike

我正在开发 Outlook 加载项,最近为了熟悉而切换到 C#(我本质上是一个 Java 人)。此时,我只是尝试遍历邮件文件夹并将每条消息的主题打印到控制台,主要是为了确保到目前为止一切正常。但是,每当我运行它时,都会收到以下错误:

Could not complete the operation. One or more parameter values are not valid.

异常文本:

System.ArgumentException: Could not complete the operation. One or more parameter values are not valid. at Microsoft.Office.Interop.Outlook.NameSpaceClass.GetFolderFromID(String EntryIDFolder, Object EntryIDStore) at OutlookAddIn2.ThisAddIn.ThisAddIn_Startup(Object sender, EventArgs e) at Microsoft.Office.Tools.AddInImpl.OnStartup() at Microsoft.Office.Tools.AddInImpl.AddInExtensionImpl.Microsoft.Office.Tools.EntryPoint.OnStartup() at Microsoft.Office.Tools.AddInBase.OnStartup() at OutlookAddIn2.ThisAddIn.FinishInitialization() at Microsoft.Office.Tools.AddInBase.Microsoft.Office.Tools.EntryPoint.FinishInitialization() at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.ExecutePhase(ExecutionPhases executionPhases) at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()

加载的程序集:

我对此感到有些困惑,因为这是 Microsoft 在 MSDN 上推荐的让用户选择文件夹的精确方法。我已经包含了我的来源,如果您有任何想法,请告诉我。感谢您花时间阅读这篇文章,并愿意提供帮助!

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

namespace OutlookAddIn2
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
//Get application namespace and grab the original folder object
Outlook.Folder pickFolder = (Outlook.Folder)Application.Session.PickFolder();

//Outlook.Folder mrFolder = Application.Session.GetFolderFromID(pickFolder.EntryID, pickFolder.StoreID) as Outlook.Folder;

foreach (Outlook.MailItem oMailItem in pickFolder.Items)
{
Console.WriteLine(oMailItem.Subject);
}
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

#region VSTO generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}

最佳答案

托盘这个:

 public static Folder FOLDER_1;
public static Folder FOLDER_2;
public static Folder FOLDER_N;

/// <summary>
/// Hilo que lee el archivo de datos PST del OUTLOOK
private static void readPst()
{
try
{
Application app = new Application();
NameSpace outlookNs = app.GetNamespace("MAPI");
MAPIFolder mf = outlookNs.GetDefaultFolder(OlDefaultFolders.olFolderTasks);


string names = mf.FolderPath.Split('\\')[2];



Folder fMails = getFolder(fCarpetasPersonales.Folders, "Inbox");



FOLDER_1= getFolder(fMails.Folders, "FOLDER_1");
FOLDER_2= getFolder(fMails.Folders, "FOLDER_2");
FOLDER_N= getFolder(fMails.Folders, "FOLDER_n");

//TO DO... For example: foreach (object item in fMails.Items)



private static Folder getFolder(Folders folders, string folder)
{
foreach (object item in folders)
{
if (item is Folder)
{
Folder f = (Folder)item;
if (f.Name.Equals(folder))
{
return f;
}
}
}
return null;
}

关于c# - 在 C# 中访问 Outlook 2010 邮件文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11416633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com