コード例 #1
0
        public static bool MoveMail(string entryId, string newFolderName)
        {
            var application = new Application();

            application.Session.Logon();

            if (application.Session == null)
            {
                return(false);
            }

            MAPIFolder destFldr = null;

            foreach (MAPIFolder folder in application.Session.Folders)
            {
                destFldr = GetFolder(folder, newFolderName);

                if (destFldr != null)
                {
                    break;
                }
            }

            if (destFldr == null)
            {
                return(false);
            }

            try
            {
                var rdo = new RDOSession();

                rdo.MAPIOBJECT = application.Session.MAPIOBJECT;

                var rdoMail = rdo.GetMessageFromID(entryId);

                if (rdoMail == null)
                {
                    return(false);
                }

                var rodFolder = rdo.GetFolderFromID(destFldr.EntryID);

                rdoMail.Move(rodFolder);

                return(true);
            }
            catch
            {
                return(false);
            }
        }