private void getMails() { Rfc822Message message; mail_recibido mailRecibido = new mail_recibido(); string uidl; if (recibidos) { Cargando carg = new Cargando(); carg.Ejecutar(); //sincronización mails. client = G.crear_cliente(); int ciclos = 0; while (client.ConnectionState != EPop3ConnectionState.Authenticated) { Thread.Sleep(100); ciclos++; if (ciclos > 120) { break; } } Pop3MessageUIDInfoCollection messageUIDs = client.GetAllUIDMessages(); uint i = 1; foreach (Pop3MessageUIDInfo uidInfo in messageUIDs) { uidl = uidInfo.UniqueNumber; if (!G.user.exists_mailRecibido(uidl)) { message = client.GetMessage(i); //guardo mail mailRecibido.__uidl = uidl; mailRecibido.__remitente_nombre = message.From.DisplayName.ToString(); mailRecibido.__remitente_mail = message.From.Address.ToString(); if (message.From.Address == client.Username) { mailRecibido.__asunto = null; } else { mailRecibido.__asunto = message.Subject.ToString(); } mailRecibido.__mensaje = message.Text.ToString(); mailRecibido.__fecha = message.Date.ToLocalTime(); G.user.guardarMailRecibido(mailRecibido); } i++; } client.Logout(); carg.Detener(); } }
public bool eliminar_mail(string UIDL) { Cargando carg = new Cargando(); carg.Ejecutar(); client = G.crear_cliente(); Pop3MessageUIDInfoCollection messageUIDs = client.GetAllUIDMessages(); uint i = 1; foreach (Pop3MessageUIDInfo uidInfo in messageUIDs) { if (uidInfo.UniqueNumber == UIDL) { client.DeleteMessage(i); break; } i++; } client.Logout(); G.user.eliminar_mail_recibido(UIDL); client.Logout(); if (((G.user.cantidad_mails_recibidos() % 8) == 1) && btnAnterior.Enabled) { btnAnterior_Click(null, EventArgs.Empty); } else { actualizar_vista(); } carg.Detener(); return(true); }
private SortedList <string, Rfc822Message> getSmtpMessages() { Pop3Client target = new Pop3Client(); target.Host = Host; //TCP port for connection target.Port = Convert.ToUInt16(Port); //Username to login to the POP3 server target.Username = Username; //Password to login to the POP3 server target.Password = Password; // SSL Interaction type Email.Net.Common.Configurations.EInteractionType interaction = default(Email.Net.Common.Configurations.EInteractionType); if (TSL) { interaction = EInteractionType.StartTLS; } else if (SSL) { interaction = EInteractionType.SSLPort; } else { interaction = EInteractionType.Plain; } target.SSLInteractionType = EInteractionType.SSLPort; target.AuthenticationType = EAuthenticationType.Login; if (authenticationType == (int)EAuthenticationType.None) { Password = ""; Username = ""; } System.Collections.Generic.SortedList <string, Rfc822Message> messages = new System.Collections.Generic.SortedList <string, Rfc822Message>(); Rfc822Message msg = null; // Login to POP server try { Pop3Response response = target.Login(); if (response.Type == EPop3ResponseType.OK) { // Retrieve Unique IDs for all messages Pop3MessageUIDInfoCollection messageUIDs = target.GetAllUIDMessages(); //Check if messages already received foreach (Pop3MessageUIDInfo uidInfo in messageUIDs) { try { msg = target.GetMessage(uidInfo.SerialNumber); } catch (Email.Net.Common.Exceptions.ConnectionException ex) { } catch (Email.Net.Common.Exceptions.AuthenticationMethodNotSupportedException ex) { } catch (System.Exception ex) { } if ((msg != null)) { if (!string.IsNullOrEmpty(UtilFunctions.findIssueTag(msg).Trim())) { if (!UtilFunctions.searchUID(uidInfo.UniqueNumber)) { // No. Add to list messages.Add(uidInfo.UniqueNumber, target.GetMessage(uidInfo.SerialNumber)); } } } if (!runFlag | !isEnabled) { break; // TODO: might not be correct. Was : Exit For } } string cnt = (messages.Count.ToString()); cnt += " SMTP messages were found"; GlobalShared.Log.Log((int)LogClass.logType.Info, cnt, false); } //Logout from the server target.Logout(); } catch (IOException ex) { GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false); } catch (Email.Net.Common.Exceptions.ConnectionException ex) { GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false); } catch (System.Exception ex) { GlobalShared.Log.Log((int)LogClass.logType.ErrorCondition, ex.Message, false); } return(messages); }