protected void btnSendEmail_Click(object sender, EventArgs e) { if (txtemailfrom.Text == "" || txtsubject.Text == "" || txtbody.Text == "") { lblmail.Text = "Please fill all mandatory fields."; lblmail.Visible = true; return; } SmtpClient smtpClient = new SmtpClient(); MailMessage mailMessage = new MailMessage(); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString); ArrayList list_emails = new ArrayList(); int i = 0; string email; con.Open(); SqlCommand cmd = new SqlCommand("Select EmailId from Employees", con); SqlDataReader read_Email = cmd.ExecuteReader(); while (read_Email.Read()) { email = read_Email.GetValue(i).ToString(); list_emails.Add(email); //Add email to a arraylist i = i + 1 - 1; } read_Email.Close(); con.Close(); //Close connection foreach (string email_to in list_emails) { if (fileAttachement.PostedFile != null) { HttpPostedFile AttachFile = fileAttachement.PostedFile; int AttachFileLength = AttachFile.ContentLength; if (AttachFileLength > 0) { string FileName = Path.GetFileName(fileAttachement.PostedFile.FileName); } } MailAddress fromAddress = new MailAddress(txtemailfrom.Text); mailMessage.From = fromAddress; mailMessage.Subject = txtsubject.Text; mailMessage.Body = txtbody.Text; string Body = ""; Body += '\n' + "From:" + txtemailfrom.Text; Body += '\n' + ""; Body += '\n' + "Subject:" + txtsubject.Text; Body += '\n' + ""; Body += '\n' + txtbody.Text; mailMessage.IsBodyHtml = true; mailMessage.Body = Body; smtpClient.Host = "localhost"; smtpClient.Credentials = new System.Net.NetworkCredential("username", "pwd"); smtpClient.Send(mailMessage); lblmail.Visible = true; lblmail.Text = "Your mail has been sent successfully"; tblemail.Visible = true; } txtemailfrom.Text = ""; txtsubject.Text = ""; txtbody.Text = ""; }
//getting error "no receipt" on<br /> smtpClient.Send(mailMessage);
mailMessage.To =email_to
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)