【问题标题】:Send email with some [text] files with TIdPOP3Server使用 TIdPOP3Server 发送包含一些 [文本] 文件的电子邮件
【发布时间】:2014-04-08 17:03:55
【问题描述】:

我在indy 10 中通过TIdPOP3ServerOnRetrieve 事件发送文本文件没有问题,但我不知道如何发送多个文件。我看到使用 SMTP 它是通过TIdAttachmentTIdMessage 实现的,但是如何将TIdAttachment 从我的TIdPOP3Server.OnRetrieve 事件发送到我的 POP3 客户端,然后我的 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])); 

【问题讨论】:

  • 请显示您的OnRetreive 事件处理程序代码。您是否使用TIdMessage 向客户发送电子邮件? TIdMessage 在 POP3 中的工作方式与在 SMTP 中的工作方式相同。如果您不使用TIdMessage,则必须手动处理 MIME。
  • 这是我的 OnRetrieve 事件:procedure POP3ServerRetrieve(aCmd: TIdCommand; AMsgNo: Integer);如果 (AMsgNO >= 1) AND (AMsgNo
  • @RemyLebeau,你能举个例子,如何通过 TIdCommand(POP3ServerOnRetrieve 事件中的第一个参数)发送 TIdMessage 吗?
  • 请编辑您的问题以添加您的代码,不要放在评论中。
  • 您不能调用Response.LoadFromFile() 来加载多个文件。每次调用都会清除上一次调用的数据。为什么不使用TIdMessage 准备电子邮件?

标签: delphi email pop3 indy10


【解决方案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;

【讨论】:

    猜你喜欢
    • 2011-04-12
    • 1970-01-01
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2012-11-01
    • 1970-01-01
    相关资源
    最近更新 更多