idpop保存内容时出现问题? |
缺席
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
我的整体代码如下:
if IdMessage1.MessageParts.AttachmentCount > 0 then
begin
AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1;
for i := 0 to IdMessage1.MessageParts.Count - 1 do
begin
if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then
begin
AdoOAEAttach.SQL.Clear;
AdoOAEAttach.Parameters.Clear;
AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)');
AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)');
AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False;
QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1;
AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName);
fName :=
Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename);
if FileExists(fName) then
DeleteFile(fName);
try
if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then
AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob);
AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName;
AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date();
AdoOAEAttach.ExecSQL;
except
ShowMessage(SysErrorMessage(GetLastError));
end;
end
else
begin
if IdMessage1.MessageParts.Items[i] is TIdText then
begin
AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text;
end;
end;
以上代码如果在没有附件的情况下就不会运行到
if IdMessage1.MessageParts.Items[i] is TIdText then
begin
AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text;
end;
这段代码,请教应该如何解决?
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
if IdMessage1.MessageParts.AttachmentCount > 0 then begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1; for i := 0 to IdMessage1.MessageParts.Count - 1 do begin if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then begin AdoOAEAttach.SQL.Clear; AdoOAEAttach.Parameters.Clear; AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)'); AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)'); AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False; QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName); fName := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename); if FileExists(fName) then DeleteFile(fName); try if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob); AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName; AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date(); AdoOAEAttach.ExecSQL; except ShowMessage(SysErrorMessage(GetLastError)); end; end end end else begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 0; for i := 0 to IdMessage1.MessageParts.Count - 1 do begin if IdMessage1.MessageParts.Items[i] is TIdText then begin AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; end; end; |
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
那這樣咧?
for i := 0 to IdMessage1.MessageParts.Count - 1 do begin if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1; AdoOAEAttach.SQL.Clear; AdoOAEAttach.Parameters.Clear; AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)'); AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)'); AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False; QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName); fName := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename); if FileExists(fName) then DeleteFile(fName); try if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob); AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName; AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date(); AdoOAEAttach.ExecSQL; except ShowMessage(SysErrorMessage(GetLastError)); end; end else begin AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 0; if IdMessage1.MessageParts.Items[i] is TIdText then AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text; end; end; |
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
小弟這麼試的, 不會出現 List Index Out of bounds 的問題
procedure TForm1.Button1Click(Sender: TObject); var fName: string; i, j, iCount: integer; begin Button1.Enabled := False; try IdPop31.Connect; iCount := IdPop31.CheckMessages; memo1.Lines.Add('mail count: ' IntToStr(iCount)); for j := 0 to iCount -1 do begin IdMessage1.Clear; IdPop31.RetrieveHeader(j 1, IdMessage1); Memo1.Lines.Add(#13#10'mail' IntToStr(j 1)); Memo1.Lines.Add('Subject: ' IdMessage1.Subject); IdMessage1.Clear; IdMessage1.NoDecode := False; IdPop31.Retrieve(j, IdMessage1); Memo1.Lines.Add('MessageParts Count: ' IntToStr(IdMessage1.MessageParts.Count)); for i := 0 to Pred(IdMessage1.MessageParts.Count) do begin Memo1.Lines.Add('MessageParts' IntToStr(i)); if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then begin fName := TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename; Memo1.Lines.Add('Attachement File Name: ' fName); end else begin if IdMessage1.MessageParts.Items[i] is TIdText then Memo1.Lines.Add(TIdText(IdMessage1.MessageParts.Items[i]).Body.Text); end; end; end; finally IdPop31.Disconnect; Button1.Enabled := True; end; end; |
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
根据大大的写法,碰到现象是有附件的时候就有邮件内容而无附件的时候就没有内容,是何原因?我代码如下:
for intIndex := 1 to inMsgCount do
begin
for i := 0 to pred(IdMessage1.MessageParts.Count) do
begin
if (IdMessage1.MessageParts.Items[i] is TIdAttachment) then
begin
AdoInsertMail.Parameters.ParamByName('HadAttach').Value := 1;
AdoOAEAttach.SQL.Clear;
AdoOAEAttach.Parameters.Clear;
AdoOAEAttach.SQL.Add('insert into OAEAttach(pkey,pripkey,attachname,attach,operator,operdate)');
AdoOAEAttach.SQL.Add('values (:pkey,:pripkey,:attachname,:attach,:operator,:operdate)');
AdoOAEAttach.Active := False; QryEAttachMaxPkey.Active := False;
QryEAttachMaxPkey.Active := True; AdoOAEAttach.Parameters.ParamByName('PKey').Value := QryEAttachMaxPkey.FieldByName('PKey').AsInteger 1;
AdoOAEAttach.Parameters.ParamByName('pripkey').Value := QryMaxPkey.FieldByName('Pkey').AsInteger 1; AdoOAEAttach.Parameters.ParamByName('attachname').Value := Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).FileName);
fName :=
Base64Decode(TIdAttachment(IdMessage1.MessageParts.Items[i]).Filename);
if FileExists(fName) then
DeleteFile(fName);
try
if TIdAttachment(IdMessage1.MessageParts.Items[i]).SaveToFile(fName) then
AdoOAEAttach.Parameters.ParamByName('attach').LoadFromFile(fName, ftBlob);
AdoOAEAttach.Parameters.ParamByName('Operator').Value := UserName;
AdoOAEAttach.Parameters.ParamByName('OperDate').Value := Date();
AdoOAEAttach.ExecSQL;
except
ShowMessage(SysErrorMessage(GetLastError));
end;
end
else
begin
if IdMessage1.MessageParts.Items[i] is TIdText then
begin
AdoInsertMail.Parameters.ParamByName('Content').Value := TIdText(IdMessage1.MessageParts.Items[i]).Body.Text;
end;
end;
end;
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |