コード例 #1
0
        public void DeleteMessages(ArrayImpl dataToDelete)
        {
            var messages = GetMessagesList(dataToDelete);

            if (messages.Count > 0)
            {
                client.DeleteMessages(messages);
                Relogon();                 // TODO: костыль. Подумать, почему падает без переподключения
            }
        }
コード例 #2
0
        public static void Run()
        {
            // Create a POP3 client
            Pop3Client client = new Pop3Client("mail.aspose.com", 110, "username", "psw");

            try
            {
                // ExStart:DeleteAllEmails
                // Delete all the messages
                client.DeleteMessages();
                // ExEnd:DeleteAllEmails
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #3
0
ファイル: Pop3Examples.cs プロジェクト: zamis/MailKit
        public static void DownloadMessages()
        {
            using (var client = new Pop3Client()) {
                client.Connect("pop.gmail.com", 995, SecureSocketOptions.SslOnConnect);

                client.Authenticate("username", "password");

                var messages = client.DownloadMessages(0, count);

                foreach (var message in messages)
                {
                    // write the message to a file
                    message.WriteTo(string.Format("{0}.msg", i));
                }

                client.DeleteMessages(0, count);

                client.Disconnect(true);
            }
        }
コード例 #4
0
        /// <inheritdoc />
        protected override void Execute(Pop3ConnectorConfig configuration)
        {
            this.Log.Debug($"Fetching the emails from {configuration.Host}:{configuration.Port}");

            try
            {
                using (var popClient = new Pop3Client())
                {
                    popClient.Connect(configuration.Host, configuration.Port, configuration.UseSsl);
                    popClient.Authenticate(configuration.UserName, configuration.Password);

                    this.Log.Debug($"Number of available messages = {popClient.Count}");
                    var numberOfMessageToProcess = Math.Min(popClient.Count, 10);
                    if (numberOfMessageToProcess == 0)
                    {
                        this.Log.Debug("Disconnect from pop without processing messages");
                        popClient.Disconnect(true);
                        return;
                    }

                    this.Log.Debug($"Number of messages to process = {numberOfMessageToProcess}");
                    var mails = popClient.GetMessages(0, numberOfMessageToProcess);

                    foreach (var mail in mails)
                    {
                        this.ProcessMails(mail);
                    }

                    this.Log.Debug($"Deleting message from 0 to {numberOfMessageToProcess}");
                    popClient.DeleteMessages(0, numberOfMessageToProcess);

                    this.Log.Debug("Disconnect from pop");
                    popClient.Disconnect(true);
                }
            }
            catch (Exception e)
            {
                this.Log.Error(e);
            }
        }