Einzelnen Beitrag anzeigen

Schucki

Registriert seit: 17. Jul 2004
158 Beiträge
 
Delphi 2010 Architect
 
#9

Re: eMails über Indy10 umleiten/tunneln?

  Alt 29. Jul 2008, 12:54
So nun habe ich erstmal weiter gemacht, ich hab es geschaft das sich mein Mailprogramm einloggt und nach Nachrichten fragt. Naja da nix in der Datenbank ist, kommt auch nix... logisch

Nun habe ich in der gleichen Anwendung mit dem SMTP Server begonnen.
Vorlage: Creating an SMTP Server

Alles super soweit, ich nutze die Datenbank vorerst nur zum checken der Daten:
User und Password alles andere vermeide ich erstmal weil manche Zugriffe auf die Grund Datenbank nicht funktionieren, er findet manche Felder nicht...

Klappt soweit auch, ich sehe die eMail bereits in der Ausgabe! Also das was im Ereigniss smtpsMsgReceive passieren soll, passiert. Meine Mail geht also von mein eMail Programm über SMTP raus, doch leider bekommt mein eMail Programm (Opera) noch nicht das Ok das die eMail aus dem Ausgangskorb in den "gesendet" Korb gelangt.

Was mach ich noch falsch?
Ich habe mal den Abschnitt angehangen wo die Ereignisse abgearbeitet werden...

Gruß Frank

Delphi-Quellcode:
procedure TForm1.smtpsException(AContext: TIdContext; AException: Exception);
begin
  acontext.Connection.IOHandler.Write(aexception.Message);
end;



procedure TForm1.smtpsExecute(AContext: TIdContext);
begin
  logSmtp.DoLogWriteString(acontext.Connection.IOHandler.ReadLn);
end;



procedure TForm1.smtpsMailFrom(ASender: TIdSMTPServerContext;
  const AAddress: string; var VAction: TIdMailFromReply);
// Here we are testing the MAIL FROM line sent to the server.
// MAIL FROM address comes in via AAddress. VAction sets the return action to
// the server.
// The following actions can be returned to the server: { mAccept, mReject }
begin
  if Pos('@', AAddress) > 0 then begin
    VAction:= mAccept;
  end else begin
    VAction := mReject;
  end;
end;



procedure TForm1.smtpsMsgReceive(ASender: TIdSMTPServerContext; AMsg: TStream;
                                 var LAction: TIdDataReply);
var lmsg:TIdMessage;
    LStream:TFileStream;
    toad,from,sub,body:string;
    abuff:tstrings;
    six:int64;

begin
  CoInitialize(nil);
  //get message size..
  six:=amsg.Size;
  LStream := TFileStream.Create(ExtractFilePath(Application.exename)
                                +'test.eml', fmCreate);
try
  //put message contents in LStream...
  LStream.CopyFrom(AMsg, 0);
finally
  FreeAndNil(LStream);
end;
  msgSmtp.NoDecode:=true;
  //Load the message into idMessage component
  msgSmtp.LoadFromFile('test.eml',false);
  lblDate.Caption:=datetostr(msgSmtp.Date);
  lblTo.Caption:=msgSmtp.Recipients.EMailAddresses;
  lblFrom.Caption:=msgSmtp.From.Address;
  lblSub.Caption:=msgSmtp.Subject;
  memSmtpData.Lines.Text:=msgSmtp.Body.Text;
{
  if msgSmtp.From.Address <> '' then begin
    ado1.TableName:='email';
    ado1.Active:=true;
    ado1.Insert;
    ado1.FieldByName('to').Text:=msgSmtp.Recipients.EMailAddresses;
    ado1.FieldByName('from').Text:= msgSmtp.From.Address;
    ado1.FieldByName('subject').Text:=msgSmtp.Subject;
    ado1.FieldByName('mbody').AsString:=msgSmtp.Body.Text;
    //Date: Wed, 1 Feb 2006 17:34:43 +0000
    ado1.FieldByName('mdate').AsDateTime:=msgSmtp.Date;
    ado1.FieldByName('msize').value:=six;
    ado1.FieldByName('ismarked').value:=0;
    ado1.Post;
  end;
}

  CoUnInitialize;
end;



procedure TForm1.smtpsRcptTo(ASender: TIdSMTPServerContext;
  const AAddress: string; var VAction: TIdRCPToReply; var VForward: string);
begin
  // The following actions can be returned to the server:
  {
    rAddressOk, //address is okay
    rRelayDenied, //we do not relay for third-parties
    rInvalid, //invalid address
    rWillForward, //not local - we will forward
    rNoForward, //not local - will not forward - please use
    rTooManyAddresses, //too many addresses
    rDisabledPerm, //disabled permanently - not accepting E-Mail
    rDisabledTemp //disabled temporarily - not accepting E-Mail
  }

  if Pos('@', AAddress) > 0 then begin
    VAction := rAddressOk;
  end else begin
    VAction :=rInvalid;
  end;
end;



procedure TForm1.smtpsReceived(ASender: TIdSMTPServerContext;
  var AReceived: string);
begin
// This is a new event in the rewrite of IdSMTPServer for Indy 10.
// It lets you control the Received: header that is added to the e-mail.
// If you do not want a Received here to be added, set AReceived := '';
// Formatting 'keys' are available in the received header -- please check
// the IdSMTPServer source for more detail.
 AReceived := '';
end;



procedure TForm1.smtpsUserLogin(ASender: TIdSMTPServerContext; const AUsername,
  APassword: string; var VAuthenticated: Boolean);
begin
// This event is fired if a user attempts to login to the server
// Normally used to grant relay access to specific users etc.
// Search for the username and password in "users" table..
  q2.SQL.Text := 'SELECT * from users WHERE uname=:user AND upass=:pwd';
  q2.Parameters.ParamByName('user').Value :=AUsername;
  q2.Parameters.ParamByName('pwd').Value := APassword;
  q2.open;
//if the user is not found, set authentication to false
  if q2.RecordCount = 0 then begin
    VAuthenticated := False;
  end else begin
    VAuthenticated := True;
  end;
end;
Frank
  Mit Zitat antworten Zitat