![]() |
Mit Indy-SMTPServer Mails empfangen
Hi,
ich möchte gerne mit Indy E-Mails empfangen, komme aber leider nicht so wirklich weiter. Vielleicht könnt ihr mir helfen. (10.1 Berlin) Hier mal der Code, den ich bisher habe:
Delphi-Quellcode:
Im IdSMTPServer1MsgReceive tritt immer der Fehler "Socket-Fehler #10053" auf. In der Zeile " From:=LMsg.From.Text;" steigt er mir immer aus. Komischerweise kann ich den Inhalt von LMsg auch im Debugger nicht einsehen. Da steht immer "E2003: Undeklarierter Bezeichner:'LMsg'". Wahrscheinlich stelle ich mir selbst ein Bein.
unit thSMTPServer;
interface uses System.Classes, IdSMTPServer, IdMessage, System.SysUtils, IdAttachment; type TSMTPServer=class(TThread) private FPort: Integer; FIPAddress: string; FIdSMTP: TIdSMTPServer; FPendingPath: string; FTempPath: string; procedure IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext; AMsg: TStream; var LAction: TIdDataReply); procedure IdSMTPServer1UserLogin(ASender: TIdSMTPServerContext; const AUsername, APassword: String; var VAuthenticated: Boolean); procedure IdSMTPServer1RcptTo(ASender: TIdSMTPServerContext; const AAddress: String; AParams: TStrings; var VAction: TIdRCPToReply; var VForward: String); procedure IdSMTPServer1MailFrom(ASender: TIdSMTPServerContext; const AAddress: String; AParams: TStrings; var VAction: TIdMailFromReply); procedure IdSMTPServer1Received(ASender: TIdSMTPServerContext; var AReceived: String); public constructor Create(Suspended: Boolean; Port: Integer; IPAddress: string; PendingPath: string; TempPath: string); protected procedure Execute; override; end; implementation uses frmMain; { TPOP3Server } constructor TSMTPServer.Create(Suspended: Boolean; Port: Integer; IPAddress: string; PendingPath: string; TempPath: string); begin inherited Create(Suspended); FPort:=Port; FIPAddress:=IPAddress; FPendingPath:=PendingPath; FTempPath:=TempPath; FIdSMTP:=TIdSMTPServer.Create(nil); // Self.FreeOnTerminate:=true; Self.NameThreadForDebugging('SMTP-Server-Thread'); end; procedure TSMTPServer.IdSMTPServer1MailFrom(ASender: TIdSMTPServerContext; const AAddress: String; AParams: TStrings; var VAction: TIdMailFromReply); begin // 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 } // For now, we will just always allow the mail from address. VAction := mAccept; end; procedure TSMTPServer.IdSMTPServer1Received(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. end; procedure TSMTPServer.IdSMTPServer1RcptTo(ASender: TIdSMTPServerContext; const AAddress: String; AParams: TStrings; var VAction: TIdRCPToReply; var VForward: String); begin // Here we are testing the RCPT TO lines sent to the server. // These commands denote where the e-mail should be sent. // RCPT To address comes in via AAddress. VAction sets the return action to the server. // Here, you would normally do: // Check if the user has relay rights, if the e-mail address is not local // If the e-mail domain is local, does the address exist? // 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 permentantly - not accepting E-Mail rDisabledTemp //disabled temporarily - not accepting E-Mail } // For now, we will just always allow the rcpt address. VAction := rAddressOk; end; procedure TSMTPServer.IdSMTPServer1UserLogin(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. VAuthenticated := True; end; procedure TSMTPServer.IdSMTPServer1MsgReceive(ASender: TIdSMTPServerContext; AMsg: TStream; var LAction: TIdDataReply); var LMsg : TIdMessage; //LStream : TFileStream; DestinationNumber: string; From: string; i: Integer; begin // When a message is received by the server, this event fires. // The message data is made available in the AMsg : TStream. // In this example, we will save it to a temporary file, and the load it using // IdMessage and parse some header elements. LMsg := TIdMessage.Create; Try LMsg.LoadFromStream(AMsg); DestinationNumber := LMsg.Subject; From:=LMsg.From.Text; for i := 0 to LMsg.MessageParts.Count-1 do if LMsg.MessageParts.Items[i] is TIdAttachment then if (LowerCase(ExtractFileExt(LMsg.MessageParts.Items[i].FileName))='.pdf') or (LowerCase(ExtractFileExt(LMsg.MessageParts.Items[i].FileName))='.bmp') or (LowerCase(ExtractFileExt(LMsg.MessageParts.Items[i].FileName))='.jpg') then begin (LMsg.MessageParts.Items[i] as TIdAttachment).SaveToFile(FPendingPath+LMsg.MessageParts.Items[i].FileName); Synchronize(procedure begin frm_main.AddToPending(From, DestinationNumber, LMsg.MessageParts.Items[i].FileName); end); end; Finally FreeAndNil(LMsg); End; end; procedure TSMTPServer.Execute; var i: Integer; begin try if FIPAddress<>'' then begin FIdSMTP.Bindings.Clear; with FIdSMTP.Bindings.Add do IP:=FIPAddress; end; for i := 0 to FIdSMTP.Bindings.Count-1 do FIdSMTP.Bindings[i].Port:=FPort; FIdSMTP.OnMsgReceive:=IdSMTPServer1MsgReceive; FIdSMTP.OnUserLogin:=IdSMTPServer1UserLogin; FIdSMTP.OnRcptTo:=IdSMTPServer1RcptTo; FIdSMTP.OnMailFrom:=IdSMTPServer1MailFrom; FIdSMTP.OnReceived:=IdSMTPServer1Received; FIdSMTP.Active:=True; while not Terminated do begin Sleep(200); end; finally FIdSMTP.Active:=False; //self.Free; end; end; end. Leider findet sich zum Thema "SMTPServer mit Indy" nicht sehr viel im Internet. Und alles was ich gefunden habe, habe ich schon versucht hier umzusetzen. Ziel ist es den Absender, den Betreff und die Anhänge auszulesen und weiterzuverarbeiten. Gruß Hobbycoder |
AW: Mit Indy-SMTPServer Mails empfangen
Fehler 10053 heist dass die Verbindung abgebrochen ist bevor alle Daten übertragen waren
|
AW: Mit Indy-SMTPServer Mails empfangen
Hallo,
Zitat:
Es gibt massig Beispiele. Ich würde erst mal ein Minimal-Beispiel machen Form, Button, ButtonClick Also nicht gleich mit Threads anfangen. Dann das Bsp. hier posten und dann sehe ich es mir gern an. Huch: SMTP, das hatte ich überlesen, ich hatte an POP3 gedacht trotzdem bitte mal Minimal-Beispiel. |
AW: Mit Indy-SMTPServer Mails empfangen
Hallo,
![]() Antwort 1, besonders das // Do not use the TIdMessage.LoadFrom...() methods here! |
AW: Mit Indy-SMTPServer Mails empfangen
Zitat:
Zitat:
Da es sich, ob nun Thread (den einzubinden ja nicht besonders schwer ist) oder nicht, bereits hier um ein Minimalbeispiel handelt und ich die Lösung bereits von Hoika vor Augen geführt bekommen habe, schenke ich mir jetzt mal, das jetzt noch mal in eine Form zu legen. Trotzdem Danke. Gruß Hobbycoder |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:36 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz