Board index » delphi » 2d Post (urgent): eMail attachement problem ! Heelp

2d Post (urgent): eMail attachement problem ! Heelp

Hello,

I have an incoming email aMsg: tidMessage coming from a TidPop...

I would like to just forward this email to another receipiant else using a
TidSMTP

So, I changed the aMsg.Recipients list, and it work fine, execept if the
incoming mail has some attachement (test.doc), then I got an error: test.doc
not found...

What I am missing ? or how should I do ?

I've searched all the demos/samples but no mail reply or forwarding
samples... :(

Thank you,

Eric

 

Re:2d Post (urgent): eMail attachement problem ! Heelp


"Eric Friedlingstein" <e...@synapsis-group.com> schrieb im Newsbeitrag
news:3cdb64d4$1_2@dnews...

Quote
> Hello,

> I have an incoming email aMsg: tidMessage coming from a TidPop...

> I would like to just forward this email to another receipiant else using a
> TidSMTP

> So, I changed the aMsg.Recipients list, and it work fine, execept if the
> incoming mail has some attachement (test.doc), then I got an error:
test.doc
> not found...

> What I am missing ? or how should I do ?

> I've searched all the demos/samples but no mail reply or forwarding
> samples... :(

a) I hope, you will not built a spam prog.
b) do not decode the message, header and body are poor stringlists.
c) TidSmtp is not designed for relays. Therefor i use the following unit:
------------------------------------
unit IdServSMTPCli;

interface

uses
  Classes,
  IdSMTP,
  IdNNTP;

type
  TIdServSMTPCli = class (TidSMTP)
  protected

  public
    DerAbsender : string;
    DieEmpfaenger, DerHeader, DerBody : TStrings;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function SendX: integer; virtual;
  end;
{
SendX Fehler: 1 = Absender, 2 = ein Empf?nger 3 = kein gltiger Empf?nger
4 = es werden keine Nutzdaten angenommen

Quote
}

  TidNNTPGe = class(TIdNNTP)

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function SelectGroupGe(const AGroup: string) : boolean;
  end;

implementation

{uses
  IdCoder3To4,
  IdGlobal,
  IdResourceStrings,
  SysUtils;  }

{ TidNNTP }

constructor TidNNTPGe.Create(AOwner: TComponent);
begin
  inherited;
end;

destructor TidNNTPGe.Destroy;
begin
  inherited;
end;

function TidNNTPGe.SelectGroupGe(const AGroup: string) : boolean;
begin
  Result := true;
  try
    SelectGroup(AGroup);
  except
    Result := false;
  end;
end;

{ TIdSMTP }

constructor TIdServSMTPCli.Create(AOwner: TComponent);
begin
  inherited;
  DieEmpfaenger := TStringList.Create;
  DerHeader     := TStringList.Create;
  DerBody       := TStringList.Create;
end;

destructor TIdServSMTPCli.Destroy;
begin
  DieEmpfaenger.Free;
  DieEmpfaenger := NIL;
  DerHeader.Free;
  DerHeader := NIL;
  DerBody.Free;
  DerBody := NIL;
  inherited;
end;

function TIdServSMTPCli.SendX: integer;
var
  ok: boolean;

  procedure WriteRecipient ( const AEmailAddress: String );
  begin
    try
      SendCmd ( 'RCPT TO:<' + AEMailAddress + '>', 250 );
      ok := true;
    except
      Result := 2;
    end;
  end;

  procedure WriteRecipients(AList: TStrings);
  var
    i: integer;
  begin
    for i := 0 to AList.count - 1 do
    begin
      if (pos('@', AList[i]) > 0) then
      WriteRecipient ( AList [ i ] );
    end;
  end;

  Function NeedToAuthenticate : Boolean;
  begin
    if FAuthenticationType <> atNone then
    begin
      Result := IsAuthProtocolAvailable ( FAuthenticationType )
        and ( FDidAuthenticate = False );
    end
    else
    begin
      Result := False;
    end;
  end;

begin
  Result := 0;
  SendCmd( 'Rset');
  if  NeedToAuthenticate then
  begin
    Authenticate;
  end;
  try
    SendCmd( 'Mail from:<' + DerAbsender + '>', 250);
  except
    Result := 1;
    Exit;
  end;
  ok := false;
  WriteRecipients(DieEmpfaenger);
  if not ok then begin
    Result := 3;
    Exit;
  end;
  try
    SendCmd( 'Data', 354 );
  except
    Result := 4;
    Exit;
  end;
  WriteStrings(DerHeader);
  WriteLn('');
  WriteStrings(DerBody);
  SendCmd( '.', 250);
  DieEmpfaenger.Clear;
  DerHeader.Clear;
  DerBody.Clear;
end;

end.
--------------------------------

hth Ernst

Other Threads