protected void MailSend(string from, string to, string subject, string body) { //Test Email Data string strdir = "D:\\TEMP\\"; string AttFileName = Label2.Text.ToString(); string filelocation = strdir + AttFileName; //client = new SmtpClient(); //client.Host = "localhost"; //client.Port = 25; try { bool T1; GoofyMailSender mail = new GoofyMailSender("localhost"); T1 = mail.SendMailWithAttachment(to, from, subject, body, ""); if (T1 == false) { Response.Write("<script>alert('Email address Error, Your Mail do not send,Please check recipient mail '); </script>"); } else { if (PDFCheckBox.Checked == true) { mail.AttachFile(filelocation); } mail.MailSend(); updateEmailhistory(to, subject, body, from); //File.Delete(filelocation); } } catch { //File.Delete(filelocation); Response.Write("<script>alert('Email address Error, Your Mail do not send '); indow.close();</script>"); } finally { Response.Write("Your E-mail has been sent sucessfully"); Response.Write("<script>window.close();</script>"); } }
//MAIL SEND protected void btnEmail_Click() { //FILE Location string strFileName; string PdfFile; int X = 0; //Mail Info for (int rowIndex = 0; rowIndex < GridViewHAWB.Rows.Count; rowIndex++) { try { // Mail Check box CheckBox MainBox = (CheckBox)GridViewHAWB.Rows[rowIndex].FindControl("MainCheckBox"); // Get HAWB Checkbox CheckBox HAWBox = (CheckBox)GridViewHAWB.Rows[rowIndex].FindControl("HAWBCheckBox"); if (MainBox.Checked == true) { // Mail shipper mail to TextBox txtTo = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("Txtshipper_email"); // Mail subject TextBox txtSubject = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("TxtSubject"); // Mail Body TextBox txtBody = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("txtBody"); // Consignee Name TextBox txtConsigneeName = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("txtConsignee_name"); // Mail Consignee mail TO TextBox txtConsigneeEmail = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("Txtconsignee_email"); TextBox txtShipperName = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("txtShipper_Name"); // Mail CC TextBox txtCC = (TextBox)GridViewHAWB.Rows[rowIndex].FindControl("txtCC"); // GET Shipper ID HiddenField orgNo = (HiddenField)GridViewHAWB.Rows[rowIndex].FindControl("hOrgNo"); // Get HAWB No HiddenField HAWBNO = (HiddenField)GridViewHAWB.Rows[rowIndex].FindControl("hHAWBNo"); // create new Client //client = new SmtpClient(); // set Host and Port //client.Host = "localhost"; //client.Port = 25; // get from , Shipper to, Consignee To, subject, Body To String Form string ShipperName = txtShipperName.Text.ToString(); string ConsigneeName = txtConsigneeName.Text.ToString(); string From = txtEmail.Text.ToString(); string Subject = txtSubject.Text.ToString(); string Body = txtBody.Text.ToString(); string ToShipper = txtTo.Text.ToString(); string ToConsignee = txtConsigneeEmail.Text.ToString(); string HAWB_num = HAWBNO.Value.ToString(); string CC_email = txtCC.Text.ToString(); string org_acct = orgNo.Value.ToString(); bool T1 = true; bool T2 = true; // Sned Mail To shipper and Consignee try { T1 = msg.SendMailWithCC(ToShipper, From, Subject, Body, CC_email, ""); if (T1 == false) { Response.Write("<script>alert('Check address! Shipper or CC address Error'); </script>"); } else { PDFAttchFile(rowIndex, HAWB_num); ALLAttchFile(rowIndex, org_acct); msg.MailSend(); if (T1 == false && emailError != "N") { Response.Write("<script>alert('Email Send Error'); </script>"); } else { updateEmailhistory(org_acct, ShipperName, ToShipper, CC_email, Subject, Body, HAWB_num, "S"); emailError = "N"; } } if (T1 != false && emailError == "N") { if (txtConsigneeName.Text.ToString() != "" && txtConsigneeEmail.Text.ToString() != "") { // mail to Consignee T2 = msg.SendMailWithAttachment(ToConsignee, From, Subject, Body, ""); if (T2 == false) { Response.Write("<script>alert('Check address! Consignee Emai address Error'); </script>"); } else { PDFAttchFile(rowIndex, HAWB_num); ALLAttchFile(rowIndex, org_acct); msg.MailSend(); if (T2 == false && emailError != "N") { Response.Write("<script>alert('Email Send Error'); </script>"); } else { updateEmailhistory(org_acct, ConsigneeName, ToConsignee, CC_email, Subject, Body, HAWB_num, "C"); Response.Write("<script>alert('Shipper and Consignee Email Send'); </script>"); } } } else { Response.Write("<script>alert('Shipper Email Send'); </script>"); } } } catch { //if shipper email Error Response.Write("<script>alert(' Email address Error'); self.close();</script>"); } } else { MainBox.Checked = true; HAWBox.Checked = true; } } catch { } //Response.Write("<script>window.history.back();</script>"); } }