コード例 #1
0
ファイル: TestNetMAPI.cs プロジェクト: shahshyam/MapiEx
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function reads an appointment from the Calendar
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void AppointmentTest(NetMAPI mapi)
        {
            if (mapi.OpenCalendar() && mapi.GetContents())
            {
                mapi.SortContents(false, SortFields.SORT_RECEIVED_TIME);

                MAPIAppointment appointment;
                StringBuilder strText = new StringBuilder(NetMAPI.DefaultBufferSize);
                if (mapi.GetNextAppointment(out appointment))
                {
                    if (appointment.GetSubject(strText)) Console.WriteLine("Subject: " + strText);
                    if (appointment.GetLocation(strText)) Console.WriteLine("Location: " + strText);
                    if (appointment.GetStartTime(strText)) Console.WriteLine("Start Time: " + strText);
                    if (appointment.GetEndTime(strText)) Console.WriteLine("End Time: " + strText);

                    appointment.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: TestNetMAPI.cs プロジェクト: shahshyam/MapiEx
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function deletes the first message from the Inbox 
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

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

                    mapi.Folder.DeleteMessage(message);
                    message.Dispose();
                }
            }
        }
コード例 #3
0
ファイル: TestNetMAPI.cs プロジェクト: shahshyam/MapiEx
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // 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();
                }
            }
        }
コード例 #4
0
ファイル: TestNetMAPI.cs プロジェクト: shahshyam/MapiEx
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function moves the first message from the Inbox to the Sent Items folder (requested by user)
        //
        // NOTE: MAPIEx takes care of the internal folder, but in this case you have an external folder that must 
        // be disposed of.
        // 
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

                MAPIMessage message;
                StringBuilder s = new StringBuilder(NetMAPI.DefaultBufferSize);
                if (mapi.GetNextMessage(out message))
                {
                    Console.Write("Moving 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 sentItems = mapi.OpenSentItems(false);
                    if (mapi.Folder.MoveMessage(message, sentItems))
                    {
                        Console.WriteLine("Message moved successfully");
                    }
                    sentItems.Dispose();
                    message.Dispose();
                }
            }
        }
コード例 #5
0
ファイル: TestNetMAPI.cs プロジェクト: shahshyam/MapiEx
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // This function displays your first contact in your Contacts folder
        //
        // To do this:
        //		-first open up a MAPI session and login
        //		-then open the message store you want to send 
        //		-open your contacts folder 
        //
        // Use GetName to get the name (default DISPLAY NAME, but can be Initials, First Name etc) 
        // Use GetEmail to get the email address (named property) 
        // Use GetAddress to get the mailing address of CContactAddress::AddressType
        // Use GetPhoneNumber supplying a phone number property (ie BUSINESS_TELEPHONE_NUMBER)
        // Use GetNotes to get the notes in either plain text (default) or RTF
        //
        // Remember to Dispose of the contact when you're done with it!
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public static void ContactsTest(NetMAPI mapi)
        {
            if (mapi.OpenContacts() && mapi.GetContents())
            {
                // sort by name (stored in PR_SUBJECT)
                mapi.SortContents(true, SortFields.SORT_SUBJECT);

                MAPIContact contact;
                StringBuilder strText = new StringBuilder(NetMAPI.DefaultBufferSize);
                if (mapi.GetNextContact(out contact))
                {
                    if (contact.GetName(strText, MAPIContact.NameType.DISPLAY_NAME)) Console.WriteLine("Contact: " + strText);
                    if (contact.GetEmail(strText)) Console.WriteLine("Email: " + strText);
                    if (contact.GetCategories(strText)) Console.WriteLine("Categories: " + strText);

                    MAPIContact.ContactAddress address;
                    if (contact.GetAddress(out address, MAPIContact.AddressType.BUSINESS))
                    {
                        Console.WriteLine(address.Street);
                        Console.WriteLine(address.City);
                        Console.WriteLine(address.StateOrProvince);
                        Console.WriteLine(address.Country);
                        Console.WriteLine(address.PostalCode);
                    }

                    if (contact.GetPhoneNumber(strText, MAPIContact.PhoneType.BUSINESS_TELEPHONE_NUMBER)) Console.WriteLine("Phone: " + strText);

                    //usually you would call GetNotesSize first to ensure the buffer is large enough
                    if (contact.GetNotes(strText, false)) Console.WriteLine("Notes: " + strText);

                    contact.Dispose();
                }
            }
        }