foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles) { if (postedFile != null && postedFile.ContentLength > 0) { string filename = Path.GetFileName(postedFile.FileName); string contentType = postedFile.ContentType; int size = FileUpload1.PostedFile.ContentLength; using (Stream fs = postedFile.InputStream) { using (var br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32) fs.Length); DataAccessLayer.SaveFile(filename, contentType, transNumber, size, bytes); Sendmail(email, filename); } } } }
public void Sendmail(string mailTo, string subject) { if(FileUpload1.HasFiles) { try { var mail = new MailMessage(); var smtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("removed", "Interview study material"); mail.To.Add(mailTo); mail.Subject = subject; mail.Body = "Please find attachment document!"; string strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName); var attachFile = new Attachment(FileUpload1.PostedFile.InputStream, strFileName); mail.Attachments.Add(attachFile); smtpServer.Port = 587; smtpServer.Credentials = new NetworkCredential("removed", "removed"); smtpServer.EnableSsl = true; smtpServer.Send(mail); } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)