Beispiel #1
0
 protected void SuccessClosedBadEmailsHandler(object sender, EventArgs e)
 {
     this.badEmailsWindow = new BadEmailsWindow(this, badEmailList);
     this.badEmailsWindow.Show();
 }
Beispiel #2
0
        private void Button_Send_Click(object sender, EventArgs e)
        {
            if (currentUser != null)
            {
                bool          fromExcel     = false;
                Regex         rgx           = new Regex(@"^\s+$");
                List <string> allEmailsList = new List <string>();
                List <string> goodEmailList = new List <string>();
                this.Enabled = false;
                badEmailList = new List <string>();

                OpenFileDialog_ExportAddressList.Disposed += MainWindowEnableHandler;
                if (rgx.IsMatch(TextBox_Emails.Text) || TextBox_Emails.Text == "")
                {
                    OpenFileDialog_ExportAddressList.Filter = "Excel Files|*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt;*.xls;*.xml;*.xml;*.xlam;*.xla;*.xlw;*.xlr;";
                    DialogResult result = OpenFileDialog_ExportAddressList.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        allEmailsList = ExcelFuncions.GetEmailsFromFile(OpenFileDialog_ExportAddressList.FileName);
                    }
                    if (result == DialogResult.Cancel || result == DialogResult.Abort)
                    {
                        OpenFileDialog_ExportAddressList.Dispose();
                    }

                    fromExcel = true;
                }
                else
                {
                    string allEmailsString = TextBox_Emails.Text;
                    allEmailsList = allEmailsString.Split('\n').ToList();
                }


                for (int i = 0; i < allEmailsList.Count; i++)
                {
                    string newEmail = allEmailsList[i];
                    if (allEmailsList.Count - 1 != i && !fromExcel)
                    {
                        newEmail = newEmail.Remove(newEmail.Count() - 1);
                    }
                    try
                    {
                        if (newEmail != null && newEmail != "" && !newEmail.Contains(Environment.NewLine))
                        {
                            MailAddress m = new MailAddress(newEmail);
                            goodEmailList.Add(newEmail);
                        }
                    }
                    catch (FormatException)
                    {
                        this.badEmailList.Add(newEmail);
                    }
                }
                SendEmail     sendEmail = new SendEmail(currentUser.GetEmail(), currentUser.GetPassword());
                List <string> emails    = goodEmailList;
                sendEmail.SendEmails(emails, mail.GetSubject(), mail.GetBody());
                Success successWindow;
                if (goodEmailList.Count > 0)
                {
                    successWindow = new Success("Laiškai išsiųsti sėkmingai!");
                    successWindow.Show();
                    if (badEmailList.Count > 0)
                    {
                        successWindow.Disposed += SuccessClosedBadEmailsHandler;
                    }
                    else
                    {
                        successWindow.Disposed += MainWindowEnableHandler;
                    }
                }
                else if (badEmailList.Count > 0)
                {
                    BadEmailsWindow badEmailsWindow = new BadEmailsWindow(this, badEmailList);
                    badEmailsWindow.Show();
                }
            }
            else
            {
                Warning warningWindow = new Warning(this, "Jūs nepasirinkote vartotojo");
                warningWindow.Show();
            }
        }