本文介绍了如何上传多个文件并作为附件发送到电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在发送多个文件作为电子邮件地址的附件时遇到问题,发送成功,但文件附件是0Kb! 以下是我的代码:i am having issues sending multiple files as an attachment to email address, the sending is successful, but the file attachments are 0Kb!below is my code: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); } } } } 电子邮件代码:Email code: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()); } } }推荐答案 这篇关于如何上传多个文件并作为附件发送到电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!