注意:如果是Asp.Net的话,需要在Web.config里配置<httpRuntime maxRequestLength="120240" executionTimeout="180" enable="true"/>,如果上传大文件(出现页面错误,就请把maxRequestLength设置大点)
if (this.fuFile.PostedFile.ContentLength > 10240) { Alert.ShowInTop("<br>操作失败【提示:附件大小不成超过10MB】!", "操作提示", MessageBoxIcon.Error); return; } MailMessage myEmail = new MailMessage(); myEmail.From = new MailAddress("support@fanxu.com"); myEmail.To.Add(txtEmail2.Text.Trim()); myEmail.Subject = txtSubject.Text.Trim(); myEmail.IsBodyHtml = false; //附件 if (this.fuFile.PostedFile.ContentLength != 0) { try { //获取所有文件(包括子文件夹中的文件) string[] files = System.IO.Directory.GetFiles(Server.MapPath(@"/TempFile/"), "*.*", System.IO.SearchOption.AllDirectories); foreach (string file in files) { //删除文件 System.IO.File.Delete(file); } } catch (Exception) { } string upFileName = this.fuFile.PostedFile.FileName; string[] strTemp = upFileName.Split('.'); string upFileExp = strTemp[strTemp.Length - 1].ToString(); ServerFileName = Server.MapPath(@"/TempFile/file." + upFileExp); this.fuFile.PostedFile.SaveAs(ServerFileName); myEmail.Attachments.Add(new Attachment(ServerFileName)); } myEmail.Body = txtBody.Text.Trim(); myEmail.BodyEncoding = Encoding.UTF8; myEmail.Priority = MailPriority.High; SmtpClient smtp = new SmtpClient("邮件名"); smtp.Credentials = new NetworkCredential("用户名", "密码"); smtp.Port = 25; smtp.EnableSsl = false; smtp.Credentials = CredentialCache.DefaultNetworkCredentials; // for( smtp.Send(myEmail);
为系统而生,为框架而死,为debug奋斗一辈子;
吃符号的亏,上大小写的当,最后死在需求上。