var
i:integer;
MailCount:integer;
idmsg:TIdMessage;
tmpFileStm:TFileStream;
tmpStm:TStream;
tmpfile:TIdAttachment;
tmpIDMsgParts:TIdMessageParts;
begin
try
try
idMsg:=TIdMessage.Create(nil);
idMsg.Clear;
idPOP31.Host:=edServer.Text;
idPOP31.Port:=StrToInt(edPort.text);
idPOP31.UserID:=edUserID.Text;
idPOP31.Password:=edPasswd.Text;
idPOP31.Connect;
MailCount:=idPOP31.CheckMessages;
Label6.Caption:=inttostr(MailCount);
for i:=1 to MailCount do
begin
if not idPOP31.Retrieve(i,idmsg) then
Showmessage('error');
tmpIDMsgParts:=idMsg.MessageParts;
tmpFile:=TIdAttachment.Create(tmpIDMsgParts);
if not tmpFIle.SaveToFile('c:\test.jpg') then
showmessage('save error');
end; except
Showmessage('Error');
end;
finally
idMsg.Free;
idPOP31.Disconnect;
end
这样在SaveFile的时候老是出错,别的信息象body subject都正确,为什么就是附件存不了?肯定有附件
i:integer;
MailCount:integer;
idmsg:TIdMessage;
tmpFileStm:TFileStream;
tmpStm:TStream;
tmpfile:TIdAttachment;
tmpIDMsgParts:TIdMessageParts;
begin
try
try
idMsg:=TIdMessage.Create(nil);
idMsg.Clear;
idPOP31.Host:=edServer.Text;
idPOP31.Port:=StrToInt(edPort.text);
idPOP31.UserID:=edUserID.Text;
idPOP31.Password:=edPasswd.Text;
idPOP31.Connect;
MailCount:=idPOP31.CheckMessages;
Label6.Caption:=inttostr(MailCount);
for i:=1 to MailCount do
begin
if not idPOP31.Retrieve(i,idmsg) then
Showmessage('error');
tmpIDMsgParts:=idMsg.MessageParts;
tmpFile:=TIdAttachment.Create(tmpIDMsgParts);
if not tmpFIle.SaveToFile('c:\test.jpg') then
showmessage('save error');
end; except
Showmessage('Error');
end;
finally
idMsg.Free;
idPOP31.Disconnect;
end
这样在SaveFile的时候老是出错,别的信息象body subject都正确,为什么就是附件存不了?肯定有附件
解决方案 »
- 请问到哪里能下载到Delphi3.0?
- delphi初学者,DBGRID如何设置column的宽度?
- 连接超时??????
- FORM窗体的继承问题
- 文件传输问题
- 各位大虾,求解
- 关于多文档窗体的问题。请问如何像office那样每增加一个窗体在菜单里增加一个对应的子菜单指向这个窗体?
- Delphi6+SQL2000,三层模式下,如何存储与读取JPG格式的图像字段?
- 如何对 ftCurrency,ftTime,ftDate型数据赋值
- 求救(三层结构问题)!!!!!!!!!!!!!!!必高分!!!!!!!!!!!!!!!!!!
- 如何可以屏蔽掉电脑上的光驱啊
- 在用quickReport做报表,我希望band中的QRlabel能动态创建,可为何创建后不显示呢?
获取信息
2、遍历判断TIdMessage.MessageParts.Items中的每一项看是不是TIdAttachment类,如果是就TIdAttachment(TIdMessage.MessageParts.Items[x]).SaveToFile方法去保存
tmpFile:=TIdAttachment.Create(tmpIDMsgParts);
if not tmpFIle.SaveToFile('c:\test.jpg') then
showmessage('save error');
这一段可能有问题用(认真去想,你就会知道,一个邮件不只是有一个附件,可能有多个,而且IdPop3将正文内容也列入MessageParts中)
for MsgPartIndex :=0 to idMsg.MessageParts.Items.Count do
begin
if (idMsg.MessageParts.Items[MsgPartIndex] is TIdAttachment) then
begin{是附件}
(idMsg.MessageParts.Items[MsgPartIndex] as TIdAttachment).SaveToFile('AT'+IntToStr(MsgPartIndex)+'-'+SaveFileName);
end
else begin{如果不是应该就是属于文本型一类的TIdText}
end;
end;