我在indy 10中通过OnRetrieve
TIdPOP3Server
事件发送文本文件没有问题,但我不知道如何发送多个文件。我看到SMTP使用TIdAttachment
来实现TIdMessage
,但如何从我的TIdAttachment
事件发送TIdPOP3Server.OnRetrieve
到我的POP3客户端,然后可以读取已发送的文件这个:
if MsgDecode.MessageParts[i] Is TIdAttachment then begin
(MsgDecode.MessageParts[i] as TIdAttachment).SaveToFile((MsgDecode.MessageParts[j] as TIdAttachment).FileName);
任何人都可以帮我解决这个问题吗?
这是我的OnRetrieve事件:
procedure POP3ServerRetrieve(aCmd: TIdCommand; AMsgNo: Integer);
If (AMsgNO >= 1) AND (AMsgNo<=myMailsCount) then begin
aCmd.SendReply;
aCmd.Response.LoadFromFile('mail_filename');
aCmd.Response.LoadFromFile('mail_attachment_filename_1');
// ... loading N attachments
end
Else aCmd.Reply.SetReply(ERR,Format(' -Message %d Does not exist.',[AMsgNO]));
答案 0 :(得分:1)
请改为尝试:
procedure POP3ServerRetrieve(aCmd: TIdCommand; AMsgNo: Integer);
var
Msg: TIdMessage;
Stream: TMemoryStream;
begin
if (AMsgNO >= 1) AND (AMsgNo <= myMailsCount) then
begin
Stream := TMemoryStream.Create;
try
Msg := TIdMessage.Create;
try
// fill Msg as needed ...
Msg.SaveToStream(Stream);
finally
Msg.Free;
end;
aCmd.Reply.SetReply(OK, 'message follows');
aCmd.SendReply;
aCmd.Connection.IOHandler.Write(Stream);
finally
Stream.Free;
end;
end
else
aCmd.Reply.SetReply(ERR, Format('Message %d Does not exist.', [AMsgNO]));
end;