Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function creates a folder (opens if exists) and copies the first unread message if any to this folder
        //
        // To do this:
        //		-first open up a MAPI session and login
        //		-then open the message store you want to access 
        //		-then open the folder (probably inbox) and get the contents table
        //		-open the message you want to move
        //		-create (open if exists) the folder you want to move to
        //		-copy the message 
        //
        // You can also move and delete the message, but I wanted the sample to be non destructive just in case
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void CopyMessageTest(NetMAPI mapi)
        {
            if (mapi.OpenInbox() && mapi.GetContents())
            {
                mapi.SetUnreadOnly(true);

                MAPIMessage message;
                StringBuilder s = new StringBuilder(NetMAPI.DefaultBufferSize);
                if (mapi.GetNextMessage(out message))
                {
                    Console.Write("Copying message from '");
                    message.GetSenderName(s);
                    Console.Write(s.ToString() + "' (");
                    message.GetSenderEmail(s);
                    Console.Write(s.ToString() + "), subject '");
                    message.GetSubject(s);
                    Console.Write(s.ToString() + "'\n");

                    MAPIFolder folder=mapi.Folder;
                    MAPIFolder subfolder;
                    if (folder.CreateSubFolder("TestFolder", out subfolder)) 
                    {
                        if (folder.CopyMessage(message, subfolder))
                        {
                            Console.WriteLine("Message copied successfully");
                        }
                        subfolder.Dispose();
                    }
                    message.Dispose();
                }
            }
        }
Beispiel #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // To receive a message:
        //		-first open up a MAPI session and login
        //		-then open the message store you want to access 
        //		-then open the inbox and get the contents table
        //		-iterate through the message using GetNextMessage() (sample below gets only unread messages)
        //		-save attachments (if any) using SaveAttachment() if you like
        //
        // Remember to Dispose of the message when you're done with it!
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void ReceiveTest(NetMAPI mapi)
        {
            if (mapi.OpenInbox() && mapi.GetContents())
            {
                mapi.SortContents(false);
                mapi.SetUnreadOnly(false);

                MAPIMessage message;
                StringBuilder s = new StringBuilder(NetMAPI.DefaultBufferSize);
                while (mapi.GetNextMessage(out message))
                {
                    Console.Write("Message from '");
                    message.GetSenderName(s);
                    Console.Write(s.ToString() + "' (");
                    message.GetSenderEmail(s);
                    Console.Write(s.ToString() + "), subject '");
                    message.GetSubject(s);
                    Console.Write(s.ToString() + "', received: ");
                    message.GetReceivedTime(s);
                    Console.Write(s.ToString() + "\n\n");

                    // use message.GetBody(), message.GetHTML(), or message.GetRTF() to get the text body
                    // GetBody() can autodetect the source
                    string strBody;
                    message.GetBody(out strBody, true);
                    Console.Write(strBody + "\n");

                    message.Dispose();
                }
            }
        }