Error trying to read gmail emails from c #

1

I'm trying to read the emails in the Google inbox, the point is that when I try to execute the code it generates an error in this line

using (Pop3Client client = new Pop3Client())

The error generated is as follows:

{"Error en la inicialización del sistema de configuración"}

The code I am using to read the e obtained from the Internet which is the following:

public List<Message> getMensajes()
    {
        try
        {

            // El cliente se desconecta al terminar el using
            using (Pop3Client client = new Pop3Client())
            {
                // conectamos al servidor
                client.Connect(hostname, port, useSsl);

                // Autentificación
                client.Authenticate(username, password);

                // Obtenemos los Uids mensajes
                List<string> uids = client.GetMessageUids();

                // creamos instancia de mensajes
                List<Message> lstMessages = new List<Message>();

                // Recorremos para comparar
                for (int i = 0; i < uids.Count; i++)
                {
                    //obtenemos el uid actual, es él id del mensaje
                    string currentUidOnServer = uids[i];

                    //por medio del uid obtenemos el mensaje con el siguiente metodo
                    Message oMessage = client.GetMessage(i + 1);

                    //agregamos el mensaje a la lista que regresa el metodo
                    lstMessages.Add(oMessage);

                }

                // regresamos la lista
                return lstMessages;
            }
        }

        catch (Exception ex)
        {
            //si ocurre una excepción regresamos null, es importante que cachen las excepciones, yo
            //lo hice general por modo de ejemplo
            MensError = ex.Message;
            return null;
        }
    }

The permissions of the google account are enabled for unsafe applications and you have been given access to pop3 from the configuration, since you have an application in java that if you can access the list of inboxes, the idea is to try to do it in c # post that is going to be applied to a project aps.net mvc c #.

If someone knows what is happening and how to solve it, I appreciate it.

Updated

When executing the application, it generates the following error:

  

in System.Configuration.ClientConfigurationSystem.EnsureInit (String   configKey) in   System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem (String   sectionName) in   System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (String   sectionName) in   System.Configuration.ConfigurationManager.GetSection (String   sectionName) in   System.Configuration.PrivilegedConfigurationManager.GetSection (String   sectionName) in   System.Diagnostics.DiagnosticsConfiguration.GetConfigSection () in   System.Diagnostics.DiagnosticsConfiguration.Initialize () in   System.Diagnostics.DiagnosticsConfiguration.get_Sources () in   System.Diagnostics.TraceSource.Initialize () in   System.Net.Logging.InitializeLogging () in   System.Net.Logging.get_On () in   System.Net.Sockets.TcpClient..ctor (AddressFamily family) in   System.Net.Sockets.TcpClient..ctor () in   OpenPop.Pop3.Pop3Client.Connect (String hostname, Int32 port, Boolean   useSsl, Int32 receiveTimeout, Int32 sendTimeout,   RemoteCertificateValidationCallback certificateValidator) in   OpenPop.Pop3.Pop3Client.Connect (String hostname, Int32 port, Boolean   useSsl) in Test.listerEmailGoogle.getMessages () in   E: \ GitLab \ systems \ systems   2 \ new-characterization-system-2.0 \ Characterization-2.0 System \ Tests \ Program.cs: line   272

    
asked by Jhonny Luis 13.12.2018 в 21:37
source

0 answers