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;}}
评论中的错误列表:
>只能将赋值,调用,递增,递减和新对象表达式用作语句
>无法找到类型或命名空间名称“电子邮件”(您是否缺少using指令或程序集引用?)
>当前上下文中不存在名称“A_Sent”
>当前上下文中不存在名称“moveMail”
>当前上下文中不存在名称“SentMail”
using Outlook = Microsoft.Office.Interop.Outlook; public voID MoveMyEmails() { //set up variables outlook.application oApp = null; Outlook.MAPIFolder oSource = null; Outlook.MAPIFolder oTarget = null; try { //instantiate variables oApp = new outlook.application(); oSource = oApp.Session.GetDefaultFolder(Outlook.olDefaultFolders.olFolderSentMail); oTarget = oApp.Session.Folders["Archive"]; //loop through the folders items for (int i = oSource.Items.Count; i > 0; i--) { move the item oSource.Items[i].Move(oTarget); } } catch (Exception e) { //handle exception } //release objects if (oTarget != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oTarget); GC.WaitForPendingFinalizers(); GC.Collect(); } if (oSource != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oSource); GC.WaitForPendingFinalizers(); GC.Collect(); } if (oApp != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(oApp); GC.WaitForPendingFinalizers(); GC.Collect(); } }总结
以上是内存溢出为你收集整理的C#将邮件移至PST全部内容,希望文章能够帮你解决C#将邮件移至PST所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)