IdSMTP 與 IdConnectionIntercept 合作的問題 |
尚未結案
|
Gorden Peng
一般會員 發表:11 回覆:11 積分:4 註冊:2002-03-18 發送簡訊給我 |
我在單獨使用IdSmtp元件時,執行 IdSMTP.Connect後很快就可以連上伺服器,可是當我放上IdConnectionIntercept元件,將IdSmtp.Intercept 指向IdConnectionIntercept後,再執行IdSMTP.Connect時卻會出現"Connection Closed Gracefully"的錯誤訊息,IdConnectionIntercept元件一拿掉就又正常了。我參考了以下的連結:
http://www.swissdelphicenter.ch/en/showarticle.php?id=1
及indy in Depth電子書仍然找不出會有這種情形的原因,上面的連結有說到在client端出現這個錯誤就是一個Error,但是卻沒有說為甚麼會在Client端出現這個錯誤,這個情況看起來不是server端強破關閉連線,因為我單獨用Idsmtp就可以正常連線。
我的indy 版本是v9.0.14,有人知道如何解決這個問題嗎?
|
artist1002
高階會員 發表:2 回覆:155 積分:151 註冊:2002-09-26 發送簡訊給我 |
|
mine
中階會員 發表:28 回覆:129 積分:56 註冊:2004-03-31 發送簡訊給我 |
|
Gorden Peng
一般會員 發表:11 回覆:11 積分:4 註冊:2002-03-18 發送簡訊給我 |
很奇怪,回到家單獨寫一個只有SMTP功能的專案,放上IdConnectionIntercept元件,沒有寫任何事件。也沒問題,可以正常連線。 而我的專案中在IdConnectionIntercept中的send事件我寫了artist1002 教我的一個處理IdMessage.Body 使用 quoted-printable編碼的事件,程式碼如下:
procedure TEMailForm.IdConnectionIntercept1Send( ASender: TIdConnectionIntercept; AStream: TStream); var temp : TStringList; i : integer; tmpstr, zeroLength : pchar; begin temp := TStringList.Create; temp.LoadFromStream(AStream); //將寄送內容讀到StringList中 if temp.Count > 0 then begin for i:= 0 to temp.Count - 1 do begin if (temp.Strings[i]= 'Content-Transfer-Encoding: XQPENCODE') then //判斷傳送內容 begin temp.Strings[i] := 'Content-Transfer-Encoding: quoted-printable'; end; end; AStream.Position := 0; AStream.Size := 0; if (temp.Count > 0) then //寫回AStream begin tmpstr := PAnsiChar(temp.Text); AStream.Write( tmpstr , Length(temp.Text) ) end else begin zeroLength := #0; AStream.Write(zeroLength,1); end; end; temp.Free; end;以上程式碼是改自artist1002寫的C Builder版,不曉得改的對不對。 我有追蹤過,問題是發生在IdSmtp.connect時,不是發生在IdSmtp.send。 我的專案中有用到remobjects sdk 3.0,而remobjects中的通訊元件是以indy 的通訊元件為基礎的,如果remobjects sdk 3.0的元件中已經封裝了IdConnectionIntercept元件,一個專案中可以放兩個以上的IdConnectionIntercept元件嗎? 真的是很奇怪,單獨一個SMTP專案可以正常使用IdConnectionIntercept,但是在配有DataModual(其中有remobjects的通訊元件)的專案就無法使用IdConnectionIntercept。 我曾經把專案中的EMAIL模組分離出來,也可以正常使用IdConnectionIntercept。這真是傷腦筋了,問題不曉得出在那裡? |
artist1002
高階會員 發表:2 回覆:155 積分:151 註冊:2002-09-26 發送簡訊給我 |
引言: 很奇怪,回到家單獨寫一個只有SMTP功能的專案,放上IdConnectionIntercept元件,沒有寫任何事件。也沒問題,可以正常連線。 而我的專案中在IdConnectionIntercept中的send事件我寫了artist1002 教我的一個處理IdMessage.Body 使用 quoted-printable編碼的事件,程式碼如下:原來是要解決這個問題喔~ 我也不清楚為什麼你在Connect的時候會出現Connection Closed Gracefully的問題 可能是有通訊被擋住沒送出去導致TimeOut吧~ 至於你原本要解決CSS的問題,我有新的發現,已經不用IdConnectionIntercept來修正編碼問題。 回在原來的文章中http://delphi.ktop.com.tw/topic.php?TOPIC_ID=59329procedure TEMailForm.IdConnectionIntercept1Send( ASender: TIdConnectionIntercept; AStream: TStream); var temp : TStringList; i : integer; tmpstr, zeroLength : pchar; begin temp := TStringList.Create; temp.LoadFromStream(AStream); //將寄送內容讀到StringList中 if temp.Count > 0 then begin for i:= 0 to temp.Count - 1 do begin if (temp.Strings[i]= 'Content-Transfer-Encoding: XQPENCODE') then //判斷傳送內容 begin temp.Strings[i] := 'Content-Transfer-Encoding: quoted-printable'; end; end; AStream.Position := 0; AStream.Size := 0; if (temp.Count > 0) then //寫回AStream begin tmpstr := PAnsiChar(temp.Text); AStream.Write( tmpstr , Length(temp.Text) ) end else begin zeroLength := #0; AStream.Write(zeroLength,1); end; end; temp.Free; end;以上程式碼是改自artist1002寫的C Builder版,不曉得改的對不對。 我有追蹤過,問題是發生在IdSmtp.connect時,不是發生在IdSmtp.send。 我的專案中有用到remobjects sdk 3.0,而remobjects中的通訊元件是以indy 的通訊元件為基礎的,如果remobjects sdk 3.0的元件中已經封裝了IdConnectionIntercept元件,一個專案中可以放兩個以上的IdConnectionIntercept元件嗎? 真的是很奇怪,單獨一個SMTP專案可以正常使用IdConnectionIntercept,但是在配有DataModual(其中有remobjects的通訊元件)的專案就無法使用IdConnectionIntercept。 我曾經把專案中的EMAIL模組分離出來,也可以正常使用IdConnectionIntercept。這真是傷腦筋了,問題不曉得出在那裡? |
Gorden Peng
一般會員 發表:11 回覆:11 積分:4 註冊:2002-03-18 發送簡訊給我 |
測試了一天,知道問題在那裡了: 1.我原先依照artist1002 的 BC++Builder 版修改的IdConnectionIntercept1Send之Delphi版出了問題,我原先的程式碼如下:
procedure TEMailForm.IdConnectionIntercept1Send( ASender: TIdConnectionIntercept; AStream: TStream); var temp : TStringList; i : integer; tmpstr, zeroLength : pchar; begin temp := TStringList.Create; temp.LoadFromStream(AStream); //將寄送內容讀到StringList中 if temp.Count > 0 then begin for i:= 0 to temp.Count - 1 do begin if (temp.Strings[i]= 'Content-Transfer-Encoding: XQPENCODE') then //判斷傳送內容 begin temp.Strings[i] := 'Content-Transfer-Encoding: quoted-printable'; end; end; AStream.Position := 0; AStream.Size := 0; if (temp.Count > 0) then //寫回AStream begin tmpstr := PAnsiChar(temp.Text); AStream.Write( tmpstr , Length(temp.Text) ) end else begin zeroLength := #0; AStream.Write(zeroLength,1); end; end; temp.Free; end;以上的程式碼會讓程式在執行IdSMTP.Connect時當掉,而出現"Connection Closed Gracefully"的錯誤訊息,正確的寫法如下: procedure TForm1.IdConnectionIntercept1Send( ASender: TIdConnectionIntercept; AStream: TStream); var temp : TStringList; tmpstr : pchar; begin temp := TStringList.Create; temp.LoadFromStream(AStream); //將寄送內容讀到StringList中 if trim(temp.Text) = 'Content-Transfer-Encoding: XQPENCODE' then begin tmpstr := 'Content-Transfer-Encoding: quoted-printable'; AStream.Position := 0; AStream.Size := 0; AStream.Write( 'Content-Transfer-Encoding: quoted-printable' , Length(tmpstr)); end; temp.Free; end;因為AStream 從IdMessage.body.text所接收的資料不是一次全部傳送過來,而是一次只傳送一行,因此只要判斷每次傳進來的資料是否等於'Content-Transfer-Encoding: XQPENCODE'?如果是則將其替換成'Content-Transfer-Encoding: quoted-printable'即可。其他的資訊完全不需加以理會。底下是我記錄AStream接收到資料的次數及其內容,列出供大家參考。 0 : EHLO mail.nsysu.edu.tw 1 : RSET 2 : MAIL FROM:我們要替換的是第 23 次傳進來的字串。 要再一次的謝謝artist1002的幫忙。 |
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |