關於.net發送郵件

 if(attachment.PostedFile.FileName.Length>0)  
  {  
  //先將郵件附件上傳到服務器  
  FileUp.uploadFile   UpPic   =   new   uploadFile();  
  UpPic.iMaxSize   =   1024   *   1024   *   4;  
  UpPic.strFilter   =   "gif,jpg,bmp,jpeg,doc,xls,ppt,rar,zip,exe,pdf,txt,log,ini,mdb,mdf";  
  string[]   filenames=attachment.PostedFile.FileName.Replace("//","/").Split('/');  
  sFileName=filenames[filenames.Length-1];  
  //strImage   =DateTime.Now.ToString().Replace(":","").Replace("   ","").Replace("-","")+"."+UpPic.strExt(attachment);  
  UpPic.strSavePathName=Server.MapPath("Attach")+"/"+sFileName;  
  //imagepath   =   strImage;  
  int   revResult=UpPic.SaveFile(attachment);  
  if(revResult!=0)  
  {  
  switch(revResult)  
  {  
  case   1:  
  Msg("沒有上傳附件!");  
  break;  
  case   2:  
  Msg("您上傳的附件不能超過4M!");  
  break;  
  case   3:  
  Msg("上傳的附件格式不對!");  
  break;  
  case   4:  
  Msg("文件存放的路徑不對!");  
  break;  
  }  
  return;  
  }  
  //設置一個附件    
  System.Web.Mail.MailAttachment   mailAttachment=new   System.Web.Mail.MailAttachment(Server.MapPath("Attach")+"/"+sFileName);    
     
  //郵件附加上一個附件    
  mail.Attachments.Add(mailAttachment);    
  }  
  //SMTP服務器    
  //許多SMTP服務器都需要身份驗證    
  System.Web.Mail.SmtpMail.SmtpServer=smtpHost;    
   
  //取得用戶名  
  string[]   AddressNames=userName.Split('');  
  string   AddressName=AddressNames[0];  
     
  //驗證    
  mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",   "1");      
  //登陸名    
  mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",   AddressName);      
  //登陸密碼    
  mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",   password);      
     
  //發送    
  System.Web.Mail.SmtpMail.Send(mail);  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章