用indy收郵件的問題,怎麼樣把郵件存放到本地,最好是存到資料庫

來源:互聯網
上載者:User
用indy收郵件的問題,怎麼樣把郵件存放到本地,最好是存到資料庫 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061215094636123.html
現在用indy收郵件,郵件是可以收了,但是不知道怎麼樣最好的儲存方法,也不知道foxmail怎麼儲存的,也   不知道怎麼樣把他儲存到資料庫中,感覺他的資料庫類型比較麻煩,附件的話是不是一般都不存到資料庫中的?  
  請高手指教

可以實現的     等等寫個列子給你看~~

//****************************收取指定的郵件************************************  
  function   Trec_mail.Get_Receive(lett_index:   OleVariant):   OleVariant;  
  var  
      nmm_strUidl,nmm_strAttachFileName:string;  
      nmm_strDirName,nmm_strUrlPath:string;  
      nmm_strAttachFileUrl,nmm_strAttachFilePath:widestring;  
      nmm_index:integer;  
      nmm_strbody:widestring;  
      nmm_strdecode:string;  
  begin  
  try  
          nmg_intLetterIndex   :=strtoint(lett_index);   //全域變數郵件id  
          nmm_strUidl   :=   trim(get_uid);  
          nmg_msgBody.clear;  
          nmg_msgBody.NoDecode   :=   false;  
          nmg_msgBody.IsEncoded   :=   true;  
          try  
                nmg_pop.Retrieve(nmg_intLetterindex,nmg_msgBody);  
          except  
                result:='';  
                exit;  
          end;  
          nmg_msgHead.clear;  
          nmg_msgHead.NoDecode   :=   false;  
          nmg_msgHead.IsEncoded   :=   true;  
          try  
              nmg_pop.RetrieveHeader(nmg_intLetterIndex,nmg_msgHead);  
          except  
              result:='';  
              exit;  
          end;  
          if   nmg_strMailUserDir=''   then  
                begin  
                    nmm_strDirName   :=   nmg_strRootDir+nmm_strUidl;  
                    nmm_strUrlPath   :=   nmg_strRootUrlPath+nmm_strUidl;  
                end  
          else  
                begin  
                    nmm_strDirName   :=   nmg_strRootDir+nmg_strMailUserDir+'\'+nmm_strUidl;  
                    nmm_strUrlPath   :=   nmg_strRootUrlPath+nmg_strMailUserDir+'/'+nmm_strUidl;  
                end;  
          ForceDirectories(nmm_strDirName);  
          FormAttachHtm;  
          nmg_blnHasAttOut   :=   false;  
          //*************************本文的下載***************************************  
          try  
              if   nmg_msgBody.messageparts.Count=0   then   nmg_stsContent   :=nmg_msgBody.Body  
              else   begin  
                    for   nmm_index:=0   to   pred(nmg_msgBody.messageparts.Count)   do  
                    if   nmg_msgBody.MessageParts.Items[nmm_index]   is   TIdText   then   nmg_stsContent   :=   TIdText(nmg_msgBody.MessageParts.Items[nmm_index]).Body;  
              end;  
          except  
                result:='';  
                exit;  
          end;  
          if   (pos('HTML>',nmg_stsContent.text))or(pos('html>',nmg_stsContent.text))<1   then     nmg_stsContent.text:='<pre>'+nmg_stsContent.text+'</pre>';  
          //*************************附件的下載***************************************  
          for   nmm_index:=0   to   pred(nmg_msgBody.messageparts.Count)   do  
                  begin  
                          if   (nmg_msgBody.MessageParts.Items[nmm_index]   is   TIdAttachment)   then  
                                  begin  
                                          nmm_strAttachFileName   :=DecodeHeader(TIdAttachment(nmg_msgBody.MessageParts.Items[nmm_index]).Filename);  
                                          nmm_strAttachFileUrl   :=   nmm_strUrlPath;  
                                          nmm_strdecode:=(tidattachment(nmg_msgBody.MessageParts.Items[nmm_index]).ContentDisposition);  
                                          if   trim(nmm_strdecode)<>''   then  
                                                begin  
                                                      nmm_strAttachFilePath   :=   nmm_strDirName   +   '\attachment\'+inttostr(nmm_index);  
                                                      ForceDirectories(nmm_strAttachFilePath);  
                                                      nmm_strAttachFileUrl   :=   nmm_strAttachFileUrl+'/attachment/'+inttostr(nmm_index)+'/'+nmm_strAttachFileName;  
                                                      nmm_strAttachFilePath   :=   nmm_strAttachFilePath+'\'+nmm_strAttachFileName;  
                                                      try  
                                                      if   not   fileexists(nmm_strAttachFilePath)   then  
                                                      tidattachment(nmg_msgBody.MessageParts.Items[nmm_index]).SaveToFile(nmm_strAttachFilePath);  
                                                      except  
                                                      continue;  
                                                      end;  
                                                      nmg_stsAttach.add('<a   href="'+   nmm_strAttachFileUrl+'"   target=_blank>   '+nmm_strAttachFileName+'</a><BR><br>');  
                                                      nmg_blnHasAttOut   :=   true   ;  
                                                end  
                                          else  
                                                begin  
                                                      nmm_strAttachFilePath   :=   nmm_strDirName+'\Image\'+inttostr(nmm_index);  
                                                      nmm_strAttachFileUrl   :=   nmm_strAttachFileUrl+'\Image\'+inttostr(nmm_index)+'\'+nmm_strAttachFileName;  
                                                      ForceDirectories(nmm_strAttachFilePath);  
                                                      nmm_strAttachFilePath   :=   nmm_strAttachFilePath+'\'+nmm_strAttachFileName;  
                                                      try  
                                                      if   not   fileexists(nmm_strAttachFilePath)   then  
                                                      tidattachment(nmg_msgBody.MessageParts.Items[nmm_index]).SaveToFile(nmm_strAttachFilePath);  
                                                      except  
                                                      continue;  
                                                      end;  
                                                      //*************************替換圖片src****************  
                                                      nmg_Reg.Expression   :='src\s*=\s*"?[^\s]*@[^\s]*"?';  
                                                      nmm_strbody   :=nmg_stsContent.text;  
                                                      if   nmg_reg.Exec(nmm_strbody)   then  
                                                            begin  
                                                                nmm_strbody:=StringReplace(nmm_strbody,nmg_reg.Match[0],  
                                                                                        'src='+nmm_strAttachFileUrl,[rfReplaceAll,   rfIgnoreCase]);  
                                                                nmg_stsContent.Text   :=   nmm_strbody;  
                                                            end;  
                                                      //****************************************************  
                                                end;  
                                  end;  
                  end;  
          if   nmg_blnHasAttOut   =true   then   FinishAttachHtm(nmm_strDirName+'\mailatt.htm');  
          FinishContentHtm(nmm_strDirName+'\mailcont.htm');  
          //******************************收取完成************************************  
          nmg_reRunTimeErr:=reSuccess;  
          nmg_arrAllErrString[Ord(reGetReceiveErr)]   :=   '收取指定郵件成功.';  
  except  
          ON   E:Exception   do  
          begin  
                Result   :=   '';  
                nmg_reRunTimeErr:=reGetReceiveErr;  
                nmg_arrAllErrString[Ord(nmg_reRunTimeErr)]   :=   E.Message;  
          end;  
  end;  
      Result   :=   nmg_reRunTimeErr;  
  end;  
 

多謝高手,我先研究一下,稍後給分

to:zuoansuifeng,你代碼中的以下幾個函數的代碼能再給一下啊。  
  FormAttachHtm,DecodeHeader,FinishAttachHtm,FinishContentHtm,nmg_stsAttach  
  先謝了

zuoansuifeng好人

我自己已經搞定了    
  不過還是謝謝     zuoansuifeng(左岸)  
   
  散分結貼了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.