注意:如果是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);

相关文章:

  • 2022-02-20
  • 2021-07-04
  • 2021-05-27
  • 2022-02-26
猜你喜欢
  • 2022-12-23
  • 2021-06-07
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-07-25
相关资源
相似解决方案