Einzelnen Beitrag anzeigen

Ykcim

Registriert seit: 29. Dez 2006
Ort: NRW
804 Beiträge
 
Delphi 10.4 Sydney
 
#1

idSMTP.Connect funktioniert nicht

  Alt 2. Nov 2020, 17:29
Hallo Zusammen,

ich habe eine Anwendung auf einem Server laufen, die eMail verschickt. Nun musste ich einen Dienst bereitstellen, der das Mailing übernimmt. Dieser Dienst (VCL) läuft auf dem gleichen Server wie die Anwendung. Ich verwende die gleiche Klasse, wie in der anderen Anwendung, aber es funktioniert nicht...

Der Dienst wird zwar aufgerufen und alle Settings vorgenommen, aber beim idSMTP.Connect läuft die Anwendung ins leere...

Das doofe ist, dass es auf der Entwicklungsmaschine problemlos läuft, nur auf der Produktivmaschine nicht...

Hier der Code:
Delphi-Quellcode:
function TMail_Versand.SendEmail( Recipient : string; CCList : string; sSubject : string; Body : TStringList; Pfad : string ): boolean;
var nAlarmnr : integer;
      Attachment : TIdAttachment;
      idSMTP : TIdSMTP;
      idMessage : TIdMessage;
      MailSetPfad: string;
begin
   if Form_Main.CB_Logging.checked then
      Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Function SendEmail');
   MailSetPfad:=ExtractFilePath(ParamStr(0))+'Res\Mail.ini';
   Result := False;

   idSMTP := TidSMTP.Create;
   if Form_Main.CB_Logging.checked then
      Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': TidSMTP created');
   try
      idMessage := TidMessage.Create;
      if Form_Main.CB_Logging.checked then
         Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': TidMessage created');
      try
         idSMTP.Host := ReadFile(MailSetPfad, 'idSMTPHost');
         idSMTP.Username := ReadFile(MailSetPfad, 'idSMTPUsername');
         idSMTP.Password := ReadFile(MailSetPfad, 'idSMTPPassword');
         idSMTP.Port := StrToInt(ReadFile(MailSetPfad, 'idSMTPPort'));
         if Form_Main.CB_Logging.checked then begin
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Host: '+idSMTP.Host);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Username: '+idSMTP.Username);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Passwort: *******');
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Port: '+IntToStr(idSMTP.Port));
         end;
         idMessage.From.text := ReadFile(MailSetPfad, 'idMessageFromtext');
         idMessage.Sender.text := idMessage.From.text;
         if Form_Main.CB_Logging.checked then begin
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Absender: '+idMessage.From.text);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Sender: '+idMessage.Sender.text);
         end;
         idMessage.Recipients.EMailAddresses := Recipient;
         idMessage.CCList.EMailAddresses := CCList;
         idMessage.Subject := sSubject;
         idMessage.ContentType := ReadFile(MailSetPfad, 'idMessageContentType');

         with TidText.Create( idMessage.MessageParts, Body ) do begin
            ContentType := ReadFile(MailSetPfad, 'TidTextContentType');
         end;
         if Pfad<>'then begin
            with TIdAttachmentFile.Create( idMessage.MessageParts, Pfad ) do begin
               idMessage.MessageParts.Add( );
            end;
         end;
         if Form_Main.CB_Logging.checked then begin
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': FExceptionEmpfaenger: '+FExceptionEmpfaenger);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Recipient: '+Recipient);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': idMessageContentType: '+idMessage.ContentType);
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': TidTextContentType: '+FidTextContentType);
         end;
         try
            if Form_Main.CB_Logging.checked then
               Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Trying to Connect');
            //idSMTP.Connect(idSMTP.Host, idSMTP.Port);
            idSMTP.Connect;
            if Form_Main.CB_Logging.checked then
               Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Connected: '+BoolToStr(idSMTP.Connected));
            try
               idSMTP.Send( idMessage );
               Result := True;
               if Form_Main.CB_Logging.checked then
                  Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Send idMessage');
            finally
               idSMTP.Disconnect;
               if Form_Main.CB_Logging.checked then
                  Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': DisConnected (0):'+BoolToStr(idSMTP.Connected));
            end;
         except
         Result:= false;
         if Form_Main.CB_Logging.checked then
            Form_Main.LB_VersandLogging.Items.Add(DateTimeToStr(now())+': Connected: '+BoolToStr(idSMTP.Connected));
         end;
      finally
         idMessage.Free;
      end;
   finally
      idSMTP.Free;
   end;
end;
Ich habe ein Logging eingebaut.

So müsste es aussehen (auf der Entwicklungsmaschine)
Zitat:
02.11.2020 18:22:58: Neuer Versand in Tabelle erfasst.
02.11.2020 18:22:58: Empfänger: Max.Mustermann@domaine.com
02.11.2020 18:22:58: Betreff: Test_Mail_Local1
02.11.2020 18:22:58: Anhang: D:\HA_4966.pdf
02.11.2020 18:22:58: Vorlagen_Pfad: D:\#Programme\Mail\Mail\Win32\Debug\Res\KommentarM ailVorlage.txt
02.11.2020 18:22:58: BodySet done
02.11.2020 18:22:58: SendMail started
02.11.2020 18:22:58: Function Versand
02.11.2020 18:22:58: Function SendEmail
02.11.2020 18:22:58: TidSMTP created
02.11.2020 18:22:58: TidMessage created
02.11.2020 18:22:58: Host: sslout.df.eu
02.11.2020 18:22:58: Username: info@domaine.com
02.11.2020 18:22:58: Passwort: *******
02.11.2020 18:22:58: Port: 25
02.11.2020 18:22:58: Absender: info@domaine.com
02.11.2020 18:22:58: Sender: info@domaine.com
02.11.2020 18:22:58: FExceptionEmpfaenger:
02.11.2020 18:22:58: Recipient: Max.Mustermann@domaine.com
02.11.2020 18:22:58: idMessageContentType: multipart/*
02.11.2020 18:22:58: TidTextContentType:
02.11.2020 18:22:58: Trying to Connect
02.11.2020 18:22:58: Connected: -1
02.11.2020 18:22:58: Send idMessage
02.11.2020 18:22:58: DisConnected (0):0
02.11.2020 18:22:58: SendMail Result: -1
02.11.2020 18:22:58: SendMail finished
und So sieht es auf der ProduktivMaschine aus:
Zitat:
02.11.2020 18:16:12: Neuer Versand in Tabelle erfasst.
02.11.2020 18:16:12: Empfänger: Max.Mustermann@domaine.com
02.11.2020 18:16:12: Betreff: Test_Mail_Online
02.11.2020 18:16:12: Anhang: D:\HA_4966.pdf
02.11.2020 18:16:12: Vorlagen_Pfad: D:\Mail\Res\KommentarMailVorlage.txt
02.11.2020 18:16:12: BodySet done
02.11.2020 18:16:12: SendMail started
02.11.2020 18:16:12: Function Versand
02.11.2020 18:16:12: Function SendEmail
02.11.2020 18:16:12: TidSMTP created
02.11.2020 18:16:12: TidMessage created
02.11.2020 18:16:12: Host: sslout.df.eu
02.11.2020 18:16:12: Username: info@daomaine.com
02.11.2020 18:16:12: Passwort: *******
02.11.2020 18:16:12: Port: 25
02.11.2020 18:16:12: Absender: info@domaine.com
02.11.2020 18:16:12: Sender: info@domaine.com
02.11.2020 18:16:12: FExceptionEmpfaenger:
02.11.2020 18:16:12: Recipient: Max.Mustermann@domaine.com
02.11.2020 18:16:12: idMessageContentType: multipart/*
02.11.2020 18:16:12: TidTextContentType:
02.11.2020 18:16:12: Trying to Connect
02.11.2020 18:16:33: Connected: 0
02.11.2020 18:16:12: SendMail Result: 0
02.11.2020 18:16:33: SendMail finished
Connected ist 0 statt -1

Seht Ihr vielleicht, was ich falsch mache?

Vielen Dank
Patrick
Patrick
  Mit Zitat antworten Zitat