我想使用 C# 访问我的 Outlook 已发送文件夹并将那里的邮件移动到我的 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