Exemplo n.º 1
0
        private bool connexion_SMTP()
        {
            bool         connect = false;
            ComboBoxPort stmp    = (ComboBoxPort)comboBox_PortSMTP.SelectedItem;

            typePortSMTP = stmp.ValuePort;
            Debug.WriteLine("Numéro du port SMTP : {0}", typePortSMTP);
            FormLogin dlg = new FormLogin();

            if (dlg.ShowDialog() == true)
            {
                NetworkCredential basicCredential = new NetworkCredential(dlg.userName, dlg.login);
                smtpClient             = new SmtpClient(addr_serv_smtp.Text, typePortSMTP);
                smtpClient.Credentials = basicCredential;
                connect = true;
            }

            return(connect);
        }
Exemplo n.º 2
0
        private bool connexion_POP()
        {
            pop3Client = new Pop3Client();

            try
            {
                pop3Client.Connect(textBox_nom_serveur_POP.Text, typePortPOP, typePortPOP == 995);
            }
            catch (PopServerNotAvailableException psnae)
            {
                MessageBox.Show("Serveur POP indisponible", "Erreur", MessageBoxButton.OK);
                Debug.WriteLine("Error : {0}", psnae.ToString());
            }
            catch (PopServerNotFoundException psnfe)
            {
                MessageBox.Show("Serveur POP non trouvé", "Erreur", MessageBoxButton.OK);
                Debug.WriteLine("Error : {0}", psnfe.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur inconnue lors de la connection", "Erreur", MessageBoxButton.OK);
                Debug.WriteLine("Error : {0}", ex.ToString());
            }

            if (pop3Client.Connected)
            {
                Debug.WriteLine("Client POP connecté");
                // Récupérer le login et le nom d'utilisateur
                FormLogin dlg   = new FormLogin();
                bool      error = false;

                if (dlg.ShowDialog() == true)
                {
                    try
                    {
                        pop3Client.Authenticate(dlg.userName, dlg.login, AuthenticationMethod.Auto);

                        // Récupérer la liste des emails
                        if (pop3Client.Connected)
                        {
                            //List<string> uidList = pop3Client.GetAll();
                            int messageNumber = pop3Client.GetMessageCount();
                            Debug.WriteLine("messageNumber : {0}", messageNumber);

                            //MessageHeader head;
                            //for (int i = 0; i < messageNumber; i++)
                            //{
                            //    head = pop3Client.GetMessageHeaders(i + 1);
                            //    listMails[i] = new MailItem(i + 1, head.From.ToString(), head.Subject, head.DateSent, 50);
                            //}

                            //listView_mails.ItemsSource = listMails;
                            //listView_mails.da
                        }
                    }
                    catch (InvalidLoginException ile)
                    {
                        MessageBox.Show("Les indentifications envoyées ont été refusées par le serveur", "Erreur", MessageBoxButton.OK);
                        Debug.WriteLine("Error : {0}", ile.ToString());
                        error = true;
                    }
                    catch (PopServerLockedException psle)
                    {
                        MessageBox.Show("La boite mail a été fermée", "Erreur", MessageBoxButton.OK);
                        Debug.WriteLine("Error : {0}", psle.ToString());
                        error = true;
                    }
                    catch (ArgumentNullException ane)
                    {
                        MessageBox.Show("Le mot de passe et/ou le nom d'utilisateur sont des valeurs nulles", "Erreur", MessageBoxButton.OK);
                        Debug.WriteLine("Error : {0}", ane.ToString());
                        error = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Erreur inconnue lors de l'authentification", "Erreur", MessageBoxButton.OK);
                        Debug.WriteLine("Error : {0}", ex.ToString());
                        error = true;
                    }
                }
                else
                {
                    error = true;
                }

                if (error && pop3Client.Connected)
                {
                    pop3Client.Disconnect();
                }
            }

            return(pop3Client.Connected);
        }