public static void Run()
        {
            //ExStart:CopyMultipleMessagesFromOneFoldertoAnother
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                // Create the destination folder
                string folderName = "EMAILNET-35242";
                if (!client.ExistFolder(folderName))
                {
                    client.CreateFolder(folderName);
                }
                try
                {
                    // Append a couple of messages to the server
                    MailMessage message1 = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "EMAILNET-35242 - " + Guid.NewGuid(),
                        "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.");
                    string uniqueId1 = client.AppendMessage(message1);

                    MailMessage message2 = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "EMAILNET-35242 - " + Guid.NewGuid(),
                        "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.");
                    string uniqueId2 = client.AppendMessage(message2);

                    // Verify that the messages have been added to the mailbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection msgsColl = client.ListMessages();
                    foreach (ImapMessageInfo msgInfo in msgsColl)
                    {
                        Console.WriteLine(msgInfo.Subject);
                    }

                    // Copy multiple messages using the CopyMessages command and Verify that messages are copied to the destination folder
                    client.CopyMessages(new[] { uniqueId1, uniqueId2 }, folderName);

                    client.SelectFolder(folderName);
                    msgsColl = client.ListMessages();
                    foreach (ImapMessageInfo msgInfo in msgsColl)
                    {
                        Console.WriteLine(msgInfo.Subject);
                    }
                }
                finally
                {
                    try
                    {
                        client.DeleteFolder(folderName);
                    }
                    catch { }
                }
            }
            //ExEnd:CopyMultipleMessagesFromOneFoldertoAnother
        }
Beispiel #2
0
        public static void Run()
        {
            //ExStart:DeleteSingleMessage
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-35227 - " + Guid.NewGuid(), "EMAILNET-35227 Add ability in ImapClient to delete message");
                    string      emailId = client.AppendMessage(message);

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Select the inbox folder and Delete message
                    client.SelectFolder(ImapFolderInfo.InBox);
                    client.DeleteMessage(emailId);
                    client.CommitDeletes();
                }
                finally
                {
                }
            }
            //ExEnd:DeleteSingleMessage
        }
        public static void Run()
        {
            //ExStart:AddingNewMessage
            // Create a message
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "subject", "message");

            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host = "imap.gmail.com";
            client.Username = "******";
            client.Password = "******";
            client.Port = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // Subscribe to the Inbox folder, Append the newly created message and Disconnect to the remote IMAP server
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);
                client.AppendMessage(client.CurrentFolder.Name, msg);
                Console.WriteLine("New Message Added Successfully");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
            //ExEnd:AddingNewMessage
        }
        public static void Run()
        {
            //ExStart:AddingNewMessage
            // Create a message
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "subject", "message");

            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host            = "imap.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                // Subscribe to the Inbox folder, Append the newly created message and Disconnect to the remote IMAP server
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);
                client.AppendMessage(client.CurrentFolder.Name, msg);
                Console.WriteLine("New Message Added Successfully");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
            //ExEnd:AddingNewMessage
        }
        public static void Run()
        {
            //ExStart:DeleteSingleMessage
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-35227 - " + Guid.NewGuid(), "EMAILNET-35227 Add ability in ImapClient to delete message");
                    string emailId = client.AppendMessage(message);

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Select the inbox folder and Delete message
                    client.SelectFolder(ImapFolderInfo.InBox);
                    client.DeleteMessage(emailId);
                    client.CommitDeletes();
                }
                finally
                {

                }
            }
            //ExEnd:DeleteSingleMessage
        }
        static void Run()
        {
            // ExStart: MoveMessage
            ///<summary>
            /// This example shows how to move a message from one folder of a mailbox to another one using the ImapClient API of Aspose.Email for .NET
            /// Available from Aspose.Email for .NET 6.4.0 onwards
            /// -------------- Available API Overload Members --------------
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName)
            ///</summary>

            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                string folderName = "EMAILNET-35151";
                if (!client.ExistFolder(folderName))
                {
                    client.CreateFolder(folderName);
                }
                try
                {
                    MailMessage message = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "EMAILNET-35151 - " + Guid.NewGuid(),
                        "EMAILNET-35151 ImapClient: Provide option to Move Message");
                    client.SelectFolder(ImapFolderInfo.InBox);
                    // Append the new message to Inbox folder
                    string uniqueId = client.AppendMessage(ImapFolderInfo.InBox, message);
                    ImapMessageInfoCollection messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Now move the message to the folder EMAILNET-35151
                    client.MoveMessage(uniqueId, folderName);
                    client.CommitDeletes();
                    // Verify that the message was moved to the new folder
                    client.SelectFolder(folderName);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Verify that the message was moved from the Inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                }
                finally
                {
                    try { client.DeleteFolder(folderName); }
                    catch { }
                }
            }
            // ExEnd: MoveMessage
        }
Beispiel #7
0
        static void Run()
        {
            // ExStart: ListingMessagesWithPagingSupport
            ///<summary>
            /// This example shows the paging support of ImapClient for listing messages from the server
            /// Available in Aspose.Email for .NET 6.4.0 and onwards
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                try
                {
                    int         messagesNum  = 12;
                    int         itemsPerPage = 5;
                    MailMessage message      = null;
                    // Create some test messages and append these to server's inbox
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35157 - " + Guid.NewGuid(),
                            "EMAILNET-35157 Move paging parameters to separate class");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    // List messages from inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages();
                    // Verify the number of messages added
                    Console.WriteLine(totalMessageInfoCol.Count);

                    ////////////////// RETREIVE THE MESSAGES USING PAGING SUPPORT////////////////////////////////////

                    List <ImapPageInfo> pages        = new List <ImapPageInfo>();
                    PageSettings        pageSettings = new PageSettings();
                    ImapPageInfo        pageInfo     = client.ListMessagesByPage(itemsPerPage, 0, pageSettings);
                    Console.WriteLine(pageInfo.TotalCount);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(itemsPerPage, pageInfo.NextPage.PageOffset, pageSettings);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                    {
                        retrievedItems += folderCol.Items.Count;
                    }
                    Console.WriteLine(retrievedItems);
                }
                finally
                {
                }
            }
            // ExEnd: ListingMessagesWithPagingSupport
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            // Create a message
            Aspose.Email.Mail.MailMessage msg;
            msg = new Aspose.Email.Mail.MailMessage(
            "*****@*****.**",
            "*****@*****.**",
            "subject",
            "message"
            );

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Subscribe to the Inbox folder
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);

                // Append the newly created message
                client.AppendMessage(client.CurrentFolder.Name, msg);

                System.Console.WriteLine("New Message Added Successfully");

                //Disconnect to the remote IMAP server
                client.Disconnect();

            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
        }
Beispiel #9
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_IMAP();
            string dstEmail = dataDir + "1234.eml";

            // Create a message
            Aspose.Email.Mail.MailMessage msg;
            msg = new Aspose.Email.Mail.MailMessage(
                "*****@*****.**",
                "*****@*****.**",
                "subject",
                "message"
                );

            //Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            //Specify host, username and password for your client
            client.Host = "imap.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 993. This is the SSL port of IMAP server
            client.Port = 993;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Subscribe to the Inbox folder
                client.SelectFolder(ImapFolderInfo.InBox);
                client.SubscribeFolder(client.CurrentFolder.Name);

                // Append the newly created message
                client.AppendMessage(client.CurrentFolder.Name, msg);

                System.Console.WriteLine("New Message Added Successfully");

                //Disconnect to the remote IMAP server
                client.Disconnect();
            }
            catch (Exception ex)
            {
                System.Console.Write(Environment.NewLine + ex.ToString());
            }

            Console.WriteLine(Environment.NewLine + "Added new message on IMAP server.");
        }
        static void Run()
        { 
            // ExStart: MoveMessage
            ///<summary>
            /// This example shows how to move a message from one folder of a mailbox to another one using the ImapClient API of Aspose.Email for .NET
            /// Available from Aspose.Email for .NET 6.4.0 onwards
            /// -------------- Available API Overload Members --------------
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName, bool commitDeletions)
            /// Void ImapClient.MoveMessage(IConnection iConnection, int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(IConnection iConnection, string uniqueId, string folderName)
            /// Void ImapClient.MoveMessage(int sequenceNumber, string folderName)
            /// Void ImapClient.MoveMessage(string uniqueId, string folderName)
            ///</summary>

            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                string folderName = "EMAILNET-35151";
                if (!client.ExistFolder(folderName))
                    client.CreateFolder(folderName);
                try
                {
                    MailMessage message = new MailMessage(
                        "*****@*****.**",
                        "*****@*****.**",
                        "EMAILNET-35151 - " + Guid.NewGuid(),
                        "EMAILNET-35151 ImapClient: Provide option to Move Message");
                    client.SelectFolder(ImapFolderInfo.InBox);
                    // Append the new message to Inbox folder
                    string uniqueId = client.AppendMessage(ImapFolderInfo.InBox, message);
                    ImapMessageInfoCollection messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Now move the message to the folder EMAILNET-35151
                    client.MoveMessage(uniqueId, folderName);
                    client.CommitDeletes();
                    // Verify that the message was moved to the new folder
                    client.SelectFolder(folderName);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                    // Verify that the message was moved from the Inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    messageInfoCol1 = client.ListMessages();
                    Console.WriteLine(messageInfoCol1.Count);
                }
                finally
                {
                    try { client.DeleteFolder(folderName); }
                    catch { }
                }
            }
            // ExEnd: MoveMessage
        }
        static void Run()
        {
            // ExStart: ListingMessagesWithPagingSupport
            ///<summary>
            /// This example shows the paging support of ImapClient for listing messages from the server
            /// Available in Aspose.Email for .NET 6.4.0 and onwards
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 993, "username", "password"))
            {
                try
                {
                    int messagesNum = 12;
                    int itemsPerPage = 5;
                    MailMessage message = null;
                    // Create some test messages and append these to server's inbox
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35157 - " + Guid.NewGuid(),
                            "EMAILNET-35157 Move paging parameters to separate class");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    // List messages from inbox
                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages();
                    // Verify the number of messages added
                    Console.WriteLine(totalMessageInfoCol.Count);

                    ////////////////// RETREIVE THE MESSAGES USING PAGING SUPPORT////////////////////////////////////

                    List<ImapPageInfo> pages = new List<ImapPageInfo>();
                    ImapPageInfo pageInfo = client.ListMessagesByPage(itemsPerPage);
                    Console.WriteLine(pageInfo.TotalCount);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(pageInfo.NextPage);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                        retrievedItems += folderCol.Items.Count;
                    Console.WriteLine(retrievedItems);
                }
                finally
                {
                }
            }
            // ExEnd: ListingMessagesWithPagingSupport
        }
        public static void Run()
        {
            // Create an instance of the ImapClient class
            ImapClient client = new ImapClient();

            // Specify host, username, password, port and SecurityOptions for your client
            client.Host            = "imap.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 993;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                //ExStart:SetCustomFlag
                // Create a message
                MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "subject", "message");

                //Append the message to mailbox
                string uid = client.AppendMessage(ImapFolderInfo.InBox, message);

                //Add custom flags to the added messge
                client.AddMessageFlags(uid, ImapMessageFlags.Keyword("custom1") | ImapMessageFlags.Keyword("custom1_0"));

                //Retreive the messages for checking the presence of custom flag
                client.SelectFolder(ImapFolderInfo.InBox);

                ImapMessageInfoCollection messageInfos = client.ListMessages();
                foreach (var inf in messageInfos)
                {
                    ImapMessageFlags[] flags = inf.Flags.Split();

                    if (inf.ContainsKeyword("custom1"))
                    {
                        Console.WriteLine("Keyword found");
                    }
                }

                //ExEnd:SetCustomFlag

                Console.WriteLine("Setting Custom Flag to Message example executed successfully!");
                client.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(Environment.NewLine + ex);
            }
        }
Beispiel #13
0
        public static void Run()
        {
            try
            {
                // ExStart:RetrieveExtraParametersAsSummaryInformation
                using (ImapClient client = new ImapClient("host.domain.com", "username", "password"))
                {
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-38466 - " + Guid.NewGuid().ToString(), "EMAILNET-38466 Add extra parameters for UID FETCH command");

                    // append the message to the server
                    string uid = client.AppendMessage(message);

                    // wait for the message to be appended
                    Thread.Sleep(5000);

                    // Define properties to be fetched from server along with the message
                    string[] messageExtraFields = new string[] { "X-GM-MSGID", "X-GM-THRID" };

                    // retreive the message summary information using it's UID
                    ImapMessageInfo messageInfoUID = client.ListMessage(uid, messageExtraFields);

                    // retreive the message summary information using it's sequence number
                    ImapMessageInfo messageInfoSeqNum = client.ListMessage(1, messageExtraFields);

                    // List messages in general from the server based on the defined properties
                    ImapMessageInfoCollection messageInfoCol = client.ListMessages(messageExtraFields);

                    ImapMessageInfo messageInfoFromList = messageInfoCol[0];

                    // verify that the parameters are fetched in the summary information
                    foreach (string paramName in messageExtraFields)
                    {
                        Console.WriteLine(messageInfoFromList.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoUID.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoSeqNum.ExtraParameters.ContainsKey(paramName));
                    }
                }
                // ExEnd:RetrieveExtraParametersAsSummaryInformation
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
        public static void Run()
        {
            try
            {
                // ExStart:RetrieveExtraParametersAsSummaryInformation
                using (ImapClient client = new ImapClient("host.domain.com", "username", "password"))
                {
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "EMAILNET-38466 - " + Guid.NewGuid().ToString(), "EMAILNET-38466 Add extra parameters for UID FETCH command");

                    // append the message to the server
                    string uid = client.AppendMessage(message);

                    // wait for the message to be appended
                    Thread.Sleep(5000);

                    // Define properties to be fetched from server along with the message
                    string[] messageExtraFields = new string[] { "X-GM-MSGID", "X-GM-THRID" };

                    // retreive the message summary information using it's UID
                    ImapMessageInfo messageInfoUID = client.ListMessage(uid, messageExtraFields);

                    // retreive the message summary information using it's sequence number
                    ImapMessageInfo messageInfoSeqNum = client.ListMessage(1, messageExtraFields);

                    // List messages in general from the server based on the defined properties
                    ImapMessageInfoCollection messageInfoCol = client.ListMessages(messageExtraFields);

                    ImapMessageInfo messageInfoFromList = messageInfoCol[0];

                    // verify that the parameters are fetched in the summary information
                    foreach (string paramName in messageExtraFields)
                    {
                        Console.WriteLine(messageInfoFromList.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoUID.ExtraParameters.ContainsKey(paramName));
                        Console.WriteLine(messageInfoSeqNum.ExtraParameters.ContainsKey(paramName));
                    }
                }
                // ExEnd:RetrieveExtraParametersAsSummaryInformation
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
        public static void Run()
        {
            //ExStart:DeleteMultipleMessages
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    List<string> uidList = new List<string>();
                    const int messageNumber = 5;
                    for (int i = 0; i < messageNumber; i++)
                    {
                        MailMessage message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35226 - " + Guid.NewGuid(),
                            "EMAILNET-35226 Add ability in ImapClient to delete messages and change flags for set of messages");
                        string uid = client.AppendMessage(message);
                        uidList.Add(uid);
                    }

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Bulk Delete Messages and  Verify that the messages are deleted
                    client.DeleteMessages(uidList, true);
                    client.CommitDeletes(); 
                    messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);
                }
                finally
                {

                }
            }
            //ExStart:DeleteMultipleMessages
        }
        public static void Run()
        {
            try
            {
                // Connect to the Gmail server
                ImapClient imap = new ImapClient("imap.gmail.com", 993, "*****@*****.**", "pwd");

                // ExStart:AddingMessageToGmailFolderUsingIMAP
                // Create a message and Subscribe to the Inbox folder ans Append the newly created message
                MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "subject", "message");
                imap.SelectFolder(ImapFolderInfo.InBox);
                imap.SubscribeFolder(imap.CurrentFolder.Name);
                imap.AppendMessage(imap.CurrentFolder.Name, message);
                // ExEnd:AddingMessageToGmailFolderUsingIMAP
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #17
0
        public static void Run()
        {
            //ExStart:DeleteMultipleMessages
            using (ImapClient client = new ImapClient("exchange.aspose.com", "username", "password"))
            {
                try
                {
                    Console.WriteLine(client.UidPlusSupported.ToString());
                    // Append some test messages
                    client.SelectFolder(ImapFolderInfo.InBox);
                    List <string> uidList       = new List <string>();
                    const int     messageNumber = 5;
                    for (int i = 0; i < messageNumber; i++)
                    {
                        MailMessage message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35226 - " + Guid.NewGuid(),
                            "EMAILNET-35226 Add ability in ImapClient to delete messages and change flags for set of messages");
                        string uid = client.AppendMessage(message);
                        uidList.Add(uid);
                    }

                    // Now verify that all the messages have been appended to the mailbox
                    ImapMessageInfoCollection messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);

                    // Bulk Delete Messages and  Verify that the messages are deleted
                    client.DeleteMessages(uidList, true);
                    client.CommitDeletes();
                    messageInfoCol = null;
                    messageInfoCol = client.ListMessages();
                    Console.WriteLine(messageInfoCol.Count);
                }
                finally
                {
                }
            }
            //ExStart:DeleteMultipleMessages
        }
        static void Run()
        {
            // ExStart:SearchWithPagingSupport
            ///<summary>
            /// This example shows how to search for messages using ImapClient of the API with paging support
            /// Introduced in Aspose.Email for .NET 6.4.0
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 84, "username", "password"))
            {
                try
                {
                    // Append some test messages
                    int         messagesNum  = 12;
                    int         itemsPerPage = 5;
                    MailMessage message      = null;
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            "111111111111111");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }
                    string body = "2222222222222";
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            body);
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    ImapQueryBuilder iqb = new ImapQueryBuilder();
                    iqb.Body.Contains(body);
                    MailQuery query = iqb.GetQuery();

                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages(query);
                    Console.WriteLine(totalMessageInfoCol.Count);

                    //////////////////////////////////////////////////////

                    List <ImapPageInfo> pages    = new List <ImapPageInfo>();
                    ImapPageInfo        pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, itemsPerPage);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, pageInfo.NextPage);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                    {
                        retrievedItems += folderCol.Items.Count;
                    }
                }
                finally
                {
                }
            }
            // ExEnd: SearchWithPagingSupport
        }
        static void Run()
        { 
            // ExStart:SearchWithPagingSupport
            ///<summary>
            /// This example shows how to search for messages using ImapClient of the API with paging support
            /// Introduced in Aspose.Email for .NET 6.4.0
            ///</summary>
            using (ImapClient client = new ImapClient("host.domain.com", 84, "username", "password"))
            {
                try
                {
                    // Append some test messages
                    int messagesNum = 12;
                    int itemsPerPage = 5;
                    MailMessage message = null;
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            "111111111111111");
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }
                    string body = "2222222222222";
                    for (int i = 0; i < messagesNum; i++)
                    {
                        message = new MailMessage(
                            "*****@*****.**",
                            "*****@*****.**",
                            "EMAILNET-35128 - " + Guid.NewGuid(),
                            body);
                        client.AppendMessage(ImapFolderInfo.InBox, message);
                    }

                    ImapQueryBuilder iqb = new ImapQueryBuilder();
                    iqb.Body.Contains(body);
                    MailQuery query = iqb.GetQuery();

                    client.SelectFolder(ImapFolderInfo.InBox);
                    ImapMessageInfoCollection totalMessageInfoCol = client.ListMessages(query);
                    Console.WriteLine(totalMessageInfoCol.Count);

                    //////////////////////////////////////////////////////

                    List<ImapPageInfo> pages = new List<ImapPageInfo>();
                    ImapPageInfo pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, itemsPerPage);
                    pages.Add(pageInfo);
                    while (!pageInfo.LastPage)
                    {
                        pageInfo = client.ListMessagesByPage(ImapFolderInfo.InBox, query, pageInfo.NextPage);
                        pages.Add(pageInfo);
                    }
                    int retrievedItems = 0;
                    foreach (ImapPageInfo folderCol in pages)
                        retrievedItems += folderCol.Items.Count;
                }
                finally
                {
                }
            }
            // ExEnd: SearchWithPagingSupport
        }