using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Net; using System.Net.Security; using System.Net.Mail; using System.IO; public partial class _Default : System.Web.UI.Page { DataTable dt = new DataTable(); Excel ex = new Excel(); String sql; DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { } protected void btnupload_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) { bool uplod = true; string fleUpload = Path.GetExtension(FileUpload1.FileName.ToString()); if (fleUpload.Trim().ToLower() == ".xls" | fleUpload.Trim().ToLower() == ".xlsx") { // Save excel file into Server sub dir // to catch excel file downloading permission FileUpload1.SaveAs(Server.MapPath("~/email/" + FileUpload1.FileName.ToString())); string uploadedFile = (Server.MapPath("~/email/" + FileUpload1.FileName.ToString())); try { //dt = xlsInsert(uploadedFile); //GridView1.DataSource = dt; //GridView1.DataBind(); } catch (Exception) { uplod = false; this.lblmessage.Text = "System uploading Error"; } //File.Delete(uploadedFile); // Delete upload Excel //file in sub dir 'lsUploadFile' no need to keep... } if (uplod) { string mess1 = "File has successfully uploaded."; this.lblmessage.Text = mess1; } } else { this.lblmessage.Text = "Please select file to upload !"; } } protected void send_Click(object sender, EventArgs e) { ds.Clear(); sql = "select email from [Sheet1$]"; ds = ex.select(sql); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { int flag=0; if (ds.Tables[0].Rows[i]["email"].ToString() == "") { flag = 1; break; } #region Email MailMessage mail = new MailMessage(); mail.To.Add(ds.Tables[0].Rows[i]["email"].ToString()); mail.From = new MailAddress("deanpg@pacific-university.ac.in"); mail.Subject =subject.Text.ToUpper(); mail.Body = "<table width="100%><tr"><td width="40%>1."> Message </td>" + "<td width="60%>"" mode="hold" /> if (FileUpload2.HasFile) { mail.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName)); } mail.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; client.Credentials = new System.Net.NetworkCredential("deanpg@pacific-university.ac.in", "pacific@phd"); try { client.Send(mail); lblthen.Text = "Message has been sent succcessfully."; } catch (Exception ext) { lblmess.Text = ext.Message; } #endregion } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)