Beispiel #1
0
        private void GetNewEmails()
        {
            if (File.Exists("UserSettingInfo.xml"))
            {
                UserSettingInfoModel us        = new UserSettingInfoModel();
                XmlSerializer        XmlSerial = new XmlSerializer(typeof(UserSettingInfoModel));
                FileStream           read      = new FileStream("UserSettingInfo.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
                us = (UserSettingInfoModel)XmlSerial.Deserialize(read);
                string userAdress   = us.Adress;
                string userPassword = DecryptingPassword(us.Password);;

                using (Imap imap = new Imap())
                {
                    try
                    {
                        imap.ConnectSSL("imap.gmail.com");
                        imap.UseBestLogin(userAdress, userPassword);
                        imap.SelectInbox();
                        List <long> uids        = imap.Search(Flag.Unseen);
                        int         newmessages = uids.Count;
                        emailNumber = newmessages.ToString();
                        imap.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Wystąpiły problemy podczas logowania do skrzynki g-mail. Upewnij się, że jesteś połączony z siecią internetową.");
                    }
                }
            }
            else
            {
                MessageBox.Show("Musisz skonfigurować swoje dane dotyczące adresu e-mail oraz lokalizację");
                emailNumber = "?";
            }
        }
        private void SaveData(UserSettingInfoModel obj, string filename)
        {
            XmlSerializer serialize = new XmlSerializer(obj.GetType());
            TextWriter    writer    = new StreamWriter(filename);

            serialize.Serialize(writer, obj);
            writer.Close();
        }
 public bool AddDataAndSave(UserSettingInfoModel Us)
 {
     try
     {
         using (Imap imap = new Imap())
         {
             imap.ConnectSSL("imap.gmail.com");
             imap.UseBestLogin(Us.Adress, Us.Password);
             Us.Password = EncryptingPassword(Us.Password);
             SaveData(Us, "UserSettingInfo.xml");
             MessageBox.Show("Pomyślnie udało się zalogować do poczty g-mail.");
             return(true);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Dane nie zostały podane poprawnie i nie udało się zalogować do poczty. Upewnij się czy twoja skrzynka korzystanie z protokołu IMAP");
         return(false);
     }
 }
        //Void checking and adding user data to xml file if data are correct.
        private void button1_Click(object sender, EventArgs e)
        {
            UserSettingInfoModel UserInput = new UserSettingInfoModel();

            UserInput.Adress   = Adressemail.Text;
            UserInput.Password = PasswordEmail.Text;
            if (XMLController.isValid(UserInput))
            {
                if (XMLController.AddDataAndSave(UserInput))
                {
                    Adressemail.Text   = "";
                    PasswordEmail.Text = "";
                    panel1.Visible     = false;
                    panel2.Visible     = true;
                }
            }
            else
            {
                errorProvider1.SetError(this.Adressemail, "Uzupełnij to pole poprawnie");
                return;
            }
        }
        public bool isValid(UserSettingInfoModel model)
        {
            string emailvalidator = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

            return(Regex.IsMatch(model.Adress, emailvalidator) && model.Password != null ? true : false);
        }