我想使用C#來訪問我的Outlook發送文件夾,並將郵件移動到我的PST中稱爲存檔的文件夾中。這是我正在使用的代碼,但我收到了多個編譯錯誤。在這裏有更多的編碼經驗的人知道如何做到這一點?從評論C#將郵件移動到PST
static void MoveMe()
{
try
{
_app = new Microsoft.Office.Interop.Outlook.Application();
_ns = _app.GetNamespace("MAPI");
_ns.Logon(null, null, false, false);
Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
Outlook.Items SentMailItems = SentMail.Items;
Outlook.MailItem newEmail = null;
foreach (object collectionItem in SentMailItems)
{
moveMail.Move(Archive);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
_ns = null;
_app = null;
_inboxFolder = null;
}
}
錯誤列表:
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
The type or namespace name 'Emails' could not be found (are you missing a using directive or an assembly reference?)
The name 'A_Sent' does not exist in the current context
The name 'moveMail' does not exist in the current context
The name 'SentMail' does not exist in the current context
你的錯誤是什麼? –
1)只能使用賦值,調用,增量,減量和新的對象表達式作爲語句\t 2)他找不到類型或命名空間名稱'電子郵件'(您是否缺少using指令或程序集引用? ) 3)名稱'A_Sent'在當前上下文中不存在 4)名稱'moveMail'在當前上下文中不存在 5)名稱'SentMail'在當前上下文中不存在 – MasterOfStupidQuestions
我不得不將其標記爲脫離主題,因爲「詢問代碼的問題必須顯示對所解決問題的最小理解」,因爲您擁有的一些問題非常基本(即,「moveMail」的定義在哪裏,「SentMail」定義等)並且與您的實際問題無關。 – admdrew