public void DeleteMessages(ArrayImpl dataToDelete) { var messages = GetMessagesList(dataToDelete); if (messages.Count > 0) { client.DeleteMessages(messages); Relogon(); // TODO: костыль. Подумать, почему падает без переподключения } }
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); } }
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); } }
/// <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); } }