会发邮件了~ 怎么带附件发送呢?求教各位大虾了~~

解决方案 »

  1.   

    function Send_Mail(MailMsg:TMail):AnsiString;stdcall;
    var
      FileIndex:integer;
      a:pointer;
      AttachFile1:TMailAttach;
      AttachMent:TIdAttachment;
    begin
      if (not isInit1) then
      begin
        Result := 'SMTP_NOT_INIT';//SMTP没有初始化
        exit;
      end;  if not SMTP1.Connected then
      begin
        Result := 'SMTP_NOT_CONNECT';  //连接服务器失败
        exit;
      end;  with Msg1 do
      begin
        try
          Body.Text                   := (MailMsg.Body);
          From.Text                   := (MailMsg.FromAddress);
          Recipients.EMailAddresses   := (MailMsg.ToList_AllAddresses);
          Subject                     := (MailMsg.Subject) ;
          Priority                    := TIdMessagePriority( StrToInt((MailMsg.Priority)) );
          CCList.EMailAddresses       := (MailMsg.CcList_AllAddresses) ;
          BccList.EMailAddresses      := (MailMsg.BccList_AllAddresses)  ;
          ReceiptRecipient.Text       := (MailMsg.Receipt);
          ContentType                 := (MailMsg.ContentType);
        except
        end;    for FileIndex := 0 to High(MailMsg.AttachFile) do
        begin
          AttachFile1 := MailMsg.AttachFile[FileIndex];
          if (Length(AttachFile1.FileName)=0) then Continue;
          AttachMent := TIdAttachment.Create(MessageParts,(AttachFile1.FileName));
          //AttachMent.FileName := AttachFile1.FileName;
          //AttachMent.Assign(TPersistent(AttachFile1.AttachFile));
        end;  end;  try
        try
          SMTP1.Send(Msg1);
        finally
          Result := 'SMTP_SEND_SUCCESS';
        end;
      except
        Result := 'SMTP_SEND_FAILED';
      end;end;
      

  2.   

    TMail 参数是结构
    type TMailAttach = Record
      FileName : AnsiString;
      FileSize : Integer;
      AttachFile : TMemoryStream;
    end;type TMail = Record
      MessageId ,
      FromAddress,
      ToList_AllAddresses,
      CcList_AllAddresses,
      BccList_AllAddresses,
      Subject,
      Date,
      Receipt,
      Organization,
      Priority,
      Body,
      MailSize,
      ContentType
      :AnsiString;
      AttachFile:Array of TMailAttach;
    end;