using (MailMessage mailMessage = new MailMessage()) { mailMessage.From = new MailAddress("myname@domain.com"); mailMessage.Subject = txtSubject.Text.Trim(); mailMessage.Body = txtMessage.Text.Trim(); mailMessage.IsBodyHtml = true; mailMessage.To.Add(new MailAddress(txtTo.Text.Trim())); // Copy all seleted files to "EmailFiles" folder for sending as an attachment to mail. if (FileUpload1.HasFile || FileUpload1.FileName !="") { foreach (HttpPostedFile uploadedFile in FileUpload1.PostedFiles) { uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/EmailFiles/"), uploadedFile.FileName)); } } // Encrypt files string encryptFilePath = Request.PhysicalApplicationPath + "EmailFiles\\"; string[] S2 = Directory.GetFiles(encryptFilePath); foreach (string fileName in S2) { encryptFiles(fileName); } // looping through all the files to send files as an attachment. string UplodedfilesForEmail = Request.PhysicalApplicationPath + "EmailFiles\\"; string[] S1 = Directory.GetFiles(UplodedfilesForEmail); foreach (string fileName in S1) { mailMessage.Attachments.Add(new Attachment(fileName)); } SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.domain.com"; smtp.EnableSsl = true; System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential("emailID", "<password>"); NetworkCred.UserName = mailMessage.From.Address; NetworkCred.Password = "<password>"; smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; smtp.Port = 25; smtp.Send(mailMessage); }
EmailFiles
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)