/// <summary> /// Event raise when form load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmMain_Load(object sender, EventArgs e) { //set text for control of form to language SetUIChanges(); GetEmployeeInformation(); //SetCountCustomer(); //Linh 26-12-2014 Common.KeyChecking checkkey = new Common.KeyChecking(); if (!checkkey.checkLicense()) { lblTrial.Visible = true; btnUpGrade.Visible = true; } }
private void btnSendMail_Click(object sender, EventArgs e) { string pPathFile = ""; int totalEmail = 0; string totalMailList = ""; txtFailList.Text = string.Empty; //List check send mail fail List <string> pListFail = new List <string>(); try { progressBar1.Value = 5; if (string.IsNullOrEmpty(txtTo.Text)) { lblTB.Text = Common.clsLanguages.GetResource("CRM362"); return; } if (string.IsNullOrEmpty(txtSubject.Text.Trim())) { lblTB.Text = Common.clsLanguages.GetResource("CRM363"); return; } //Read file *.txt, para are SMTPserver, Port, bSSL, IDstr, Password, FromEmail, FromName pPathFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\setConfigurationMail.txt"; if (string.IsNullOrEmpty(pPathFile)) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM364"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } } catch (Exception exp) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM364"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } try { //progressBar1.Value = 10; string[] srr = null; //progressBar1.Value = 10; try { byte[] cryptText = System.IO.File.ReadAllBytes(pPathFile); byte[] clearText = System.Security.Cryptography.ProtectedData.Unprotect(cryptText, Common.Constants.CRYPTO_ENTROPY, DataProtectionScope.LocalMachine); string str = System.Text.Encoding.Unicode.GetString(clearText); srr = str.Split('$'); } catch (Exception exp) { CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM364"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } if (srr != null) { SMTPserver = srr[SMTP_SERVER]; Port = int.Parse(srr[SMTP_PORT]); bSSL = bool.Parse(srr[SMTP_SSL]); IDstr = srr[SENDING_MAIL]; Password = srr[SENDING_MAIL_PASS]; FromEmail = IDstr; FromName = srr[SENDING_MAIL_NAME]; //From name } //progressBar1.Value = 60; Subject = txtSubject.Text.ToString(); Body = htmlEditorControl1.InnerHtml; //TimeStamp = "\n\n\n\nNgày gửi->" + DateTime.Now.ToLocalTime(); //Body = Body + TimeStamp; //progressBar1.Value = 80; //Set para for Body mail string[] ab = new string[4]; string pName = ""; string pEmail = ""; string pBody = ""; //Linh 26-12-2014 Common.KeyChecking checkkey = new Common.KeyChecking(); for (int i = 0; i < this.arr.Count; i++) { progressBar1.Value = (int)Math.Floor((double)(100 * i / this.arr.Count)); ab = (string[])this.arr[i]; pName = ab[1]; pEmail = ab[3]; pBody = Common.clsLanguages.GetResource("CRM526") + " " + pName + "<br />"; if (Common.clsLanguages.StrCulture.Equals("ja-JP")) { pBody = pName + " " + Common.clsLanguages.GetResource("CRM526") + "<br />"; } if (checkkey.checkLicense()) { pBody = pBody + Body; } else { pBody = pBody + Body + "<p>This email is sent by VV-CRM software (trial version) - Copyright of VietVang JSC (vietvang.net).</p>"; } string[] emailArr = pEmail.Split(';'); foreach (string email in emailArr) { //Linh 03-12-2014 //Check valid list email if (!string.IsNullOrEmpty(email.Trim())) { if (IsValidEmail(email.Trim()) == false) { pListFail.Add(email); txtFailList.Text += email + "; \r\n"; } else { MailSent = sendMail(bSSL, SMTPserver, IDstr, Password, Port, FromEmail, FromName, email.Trim(), Subject, pBody, pList_attachments); if (!MailSent) { pListFail.Add(email); txtFailList.Text += email + "; \r\n"; } } totalEmail++; totalMailList += email + "; "; } } } //Linh 04-12-2014 //Gửi mail Bcc if (txtToCC.Text != "") { string[] listBcc = txtToCC.Text.Split(';'); foreach (string itemBcc in listBcc) { pEmail = itemBcc.Trim(); if ((pEmail != "") && IsValidEmail(pEmail)) { pBody = Common.clsLanguages.GetResource("CRM526") + "<br />"; pBody = pBody + Body; MailSent = sendMail(bSSL, SMTPserver, IDstr, Password, Port, FromEmail, FromName, pEmail, Subject, pBody, pList_attachments); if (!MailSent) { pListFail.Add(pEmail); txtFailList.Text += pEmail + "; \r\n"; } totalMailList += pEmail + "; "; totalEmail++; } } } progressBar1.Value = 100; //progressBar1.Value = 0; //MessageBox.Show("Mail đã gửi xong! SUCESS!,\r\n Các email gửi không được là: " + pListFailItem, "Thông báo gửi mail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (totalEmail >= pListFail.Count) { lblTB.Text = (totalEmail - pListFail.Count) + "/" + totalEmail + " " + Common.clsLanguages.GetResource("CRM603"); // Success } pList_attachments = null; //send final mail Subject = "Email(s) sending result: " + Subject; pBody = "Content:"; pBody += "<br />---------------------------------------<br />"; pBody += Body; pBody += "<br />---------------------------------------<br />"; pBody += (totalEmail - pListFail.Count) + "/" + totalEmail + " " + Common.clsLanguages.GetResource("CRM603"); pBody += "<br />-------<br />"; pBody += "Email(s) send to:<br />" + totalMailList + "<br />"; pBody += "<br />-------<br />"; pBody += "Email(s) failed:<br />" + txtFailList.Text; MailSent = sendMail(bSSL, SMTPserver, IDstr, Password, Port, FromEmail, FromName, FromEmail, Subject, pBody, pList_attachments); CustomMessageBox.MessageBox.ShowCustomMessageBox(Common.clsLanguages.GetResource("CRM649"), Common.clsLanguages.GetResource("CRM11"), Common.Config.CUSTOM_MESSAGEBOX_ICON.Information, Common.Config.CUSTOM_MESSAGEBOX_BUTTON.OK); return; } catch (Exception) { if (totalEmail >= pListFail.Count) { lblTB.Text = (totalEmail - pListFail.Count) + "/" + totalEmail + " " + Common.clsLanguages.GetResource("CRM603"); } else { lblTB.Text = Common.clsLanguages.GetResource("CRM602"); // fail } return; } }