Forward Msg with idSmtp

Giganews Newsgroups
Subject: Forward Msg with idSmtp
Posted by:  RVysata (rudolf.vysa…@creativpuls.at)
Date: Thu, 11 Oct 2007

Hi everyone,

Using Indy 10.1.5 and Delphi2007

maybe someone can give a small glue what i do wrong here:

In the SmtpServer.MsgReceive in some cases i want to forward the msg to
another Mailserver like this but in lot of cases the other mailserver return
"501 invalid Command in this state":

procedure TSpiderService.SmtpSrvMsgReceive(ASender: TIdSMTPServerContext;
  AMsg: TStream; var LAction: TIdDataReply);
var
LMsg : TIdMessage;
begin
  LMsg := TIdMessage.Create;
  lmsg.NoEncode := true;
  lmsg.NoDecode:= true;
  Try
  amsg.Position:= 0;
  LMsg.LoadFromStream(AMsg);
  try
  if idsmtp1.Connected = false  then
  idsmtp1.Connect;
  idsmtp1.Send(lmsg);
  LAction:= dOk;
  writeFile(logpath+formatdatetime('yyyymmdd',now)+'forward.txt','Forward
Msg from '+lmsg.From.Address+' to '+lmsg.Recipients.EMailAddresses);
  except  on E:Exception do begin
  lmsg.SaveToFile(errormailpath+formatdatetime('yyyymmddhhmmss',now)+'.efm');
  writeFile(logpath+formatdatetime('yyyymmdd',now)+'forward.txt','Error
forward Msg from '+lmsg.From.Address+' to '+lmsg.Recipients.EMailAddresses
+' '+E.Message);
  LAction := dTransactionFailed;
  end;
  end;
  Finally
  idsmtp1.Disconnect(true);
  FreeAndNil(LMsg);
  End;
end;

Thanks for any hints, Rudolf

Replies