Einzelnen Beitrag anzeigen

friedt99

Registriert seit: 17. Mär 2010
46 Beiträge
 
#3

AW: Indy und OAuth / Microsoft365

  Alt 5. Sep 2023, 20:00
Habe nochmal etwas gefunden und bin jetzt einen Schritt weiter.

Delphi-Quellcode:
procedure SendSMTP(ptToken:String);
Var lcSMTP:TIdSMTP;
    lcMail:TIdMessage;
    lcRec:TIdEMailAddressItem;
    lcAuthSASL:TIdSASLListEntry;
    lcProvider:TProviderInfo;
    lcIdSSLIOHandlerSocketSMTP:TidSSLIOHandlerSocketOpenSSL;
    lcUserPass:TIdUserPassProvider;
    lcDebug:TIdLogDebug;
begin
  ctToken:=ptToken;
  lcSMTP:=TIdSMTP.Create;
  Try
    lcSMTP.Host:='smtp.office365.com';
    lcSMTP.Port:=587;

    lcMail:=TIdMessage.Create(lcSMTP);
    Try
      lcMail.Encoding:=meMime;
      lcRec:=lcMail.Recipients.Add;
      lcRec.Address:='xxx@yyy.de';
      lcRec.Name:='xxx@yyy.de';

      lcMail.Subject:='Test';
      lcMail.Body.Text:='Testnachricht via OAuth';


      lcIdSSLIOHandlerSocketSMTP:=TidSSLIOHandlerSocketOpenSSL.Create(lcSMTP);
      lcIdSSLIOHandlerSocketSMTP.SSLOptions.SSLVersions:=[sslvTLSv1_2];

      lcUserPass:=TIdUserPassProvider.Create(lcSMTP);
      lcUserPass.Username:='MyMail@test.onmicrosoft.com';
      lcUserPass.Password:=ptToken;

      lcAuthSASL:=lcSMTP.SASLMechanisms.Add;
      lcAuthSASL.SASL:=TIdSASLXOAuth2.Create(lcSMTP);
      TIdSASLXOAuth2(lcAuthSASL.SASL).UserPassProvider:=lcUserPass;

      lcDebug:=TIdLogDebug.Create(lcSMTP);
      lcDebug.OnReceive:=DoAddLogReceive;
      lcDebug.OnSend:=DoAddLogSend;

      lcSMTP.Intercept:=lcDebug;
      lcSMTP.IOHandler:=lcIdSSLIOHandlerSocketSMTP;

      lcSMTP.UseTLS:=utUseExplicitTLS;
      lcSMTP.AuthType:=satSASL;
      lcSMTP.Connect;

      lcSMTP.Authenticate;
      lcSMTP.Send(lcMail);
    Finally
      lcMail.Free;
    End;
    lcSMTP.Disconnect;
  Finally
    lcSMTP.Free;
  End;
end;
Damit bekomme ich folgende Log Einträge:

Zitat:
After Access Token: {"token_type":"Bearer","expires_in":3599,"ext_expi res_in":3599,"access_token":"eyJ0eXAiOiJKV1QiLCJub 25jZSI6IjMyUGUxM3BFZXhCOE1mYklyR1RKWVllQUJ5UjdxZmR vZDh2b2c3eV9PaUEiLCJhbGciOiJSUzI1NiIsIng1dCI6Ii1LS TNROW5OUjdiUm9meG1lWm9YcWJIWkdldyIsImtpZCI6Ii1LSTN ROW5OUjdiUm9meG1lWm9YcWJIWkdldyJ9.eyJhdWQiOiJodHRw czovL2dyYXBoLm1pY3Jvc29mdC5jb20iLCJpc3MiOiJodHRwcz ovL3N0cy53aW5kb3dzLm5ldC82M2ZkZmJmMS1jYmE1LTQyNDgt YWMxZC00NDZkMDFhMGJiNGQvIiwiaWF0IjoxNjkzOTM2MTkxLC JuYmYiOjE2OTM5MzYxOTEsImV4cCI6MTY5Mzk0MDA5MSwiYWlv IjoiRTJGZ1lPaFFLTkVJVzd0ejBjbVQwYysrTEJXV0JRQT0iLC JhcHBfZGlzcGxheW5hbWUiOiJMb2dvU0lTIiwiYXBwaWQiOiJi MGM4MmZiYi03YzU0LTQwZDYtOTRkZi02MmM1NmUyOWM2YTUiLC JhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5k b3dzLm5ldC82M2ZkZmJmMS1jYmE1LTQyNDgtYWMxZC00NDZkMD FhMGJiNGQvIiwiaWR0eXAiOiJhcHAiLCJvaWQiOiJjYmJkODM0 Mi1iOWFjLTQ2OWUtOGM4Ni01YzFiYjY1OTJhZTYiLCJyaCI6Ij AuQWE0QThmdjlZNlhMU0VLc0hVUnRBYUM3VFFNQUFBQUFBQUFB d0FBQUFBQUFBQUN1QUFBLiIsInJvbGVzIjpbIlVzZXIuUmVhZC 5BbGwiLCJNYWlsLlNlbmQiXSwic3ViIjoiY2JiZDgzNDItYjlh Yy00NjllLThjODYtNWMxYmI2NTkyYWU2IiwidGVuYW50X3JlZ2 lvbl9zY29wZSI6IkVVIiwidGlkIjoiNjNmZGZiZjEtY2JhNS00 MjQ4LWFjMWQtNDQ2ZDAxYTBiYjRkIiwidXRpIjoiaFpQT0lZeU 9KVW1TU2hyWGhXSWhBQSIsInZlciI6IjEuMCIsIndpZHMiOlsi MDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl 0sInhtc190Y2R0IjoxNjkzNzU3MjM0LCJ4bXNfdGRiciI6IkVV In0.rWcKMQEYBxmloeMQ1ihVa8gLNjOTLS2_M9JpqHuMUVvdD7 E0ahECNlDnLG99nY97M8Kyvroismvn05TvgRGzKaFGzFZ4GdTX mNEAAiJ8SC_5Mcg4pGdt_34z30qQItN1j4StwNwfqV746m6EsI oY3evEBkiByw9wt98465TqSP3SCPfeOXyBlnOjNhcFw2b07Vq8 xXNxgEDeUkliuPmOpXD03SjhhLana0OaL30JJb3BvXpgg5yAwu YUKsv9ei20MlxHqZAg_pxlCrJz3-VTPVpgDlL5Fmy4GT9LX5h6pBXCZJ613AJlASEHtSGJiyrktEdn f2NrWS8c1lKbtGsNAA"}
<- 220 FR0P281CA0199.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 5 Sep 2023 17:54:51 +0000

-> EHLO VM054

<- 250-FR0P281CA0199.outlook.office365.com Hello [92.74.135.193]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8

-> STARTTLS

<- 220 2.0.0 SMTP server ready

-> EHLO VM054

<- 250-FR0P281CA0199.outlook.office365.com Hello [92.74.135.193]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
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Z19weGxDckp6My1WVFBWcGdEbEw1Rm15NEdUOUxY NWg2cEJYQ1pKNjEzQUpsQVNFSHRTR0ppeXJrdEVkbmYyTnJXUz hjMWxLYnRHc05BQQEB

<- 535 5.7.3 Authentication unsuccessful [FR0P281CA0199.DEUP281.PROD.OUTLOOK.COM 2023-09-05T17:55:02.989Z 08DBAE3606E6E73B]

Error Access Token: invalid_request Authentication unsuccessful [FR0P281CA0199.DEUP281.PROD.OUTLOOK.COM 2023-09-05T17:55:02.989Z 08DBAE3606E6E73B]
Allerdings immer noch nicht erfolgreich angemeldet. Im Azure Portal ist die Anwendung mit den entsprechenden Rechten (nach diversen Anleitungen)
eingerichtet, der SMTP Zugriff auf das Postfach ist erlaubt.

Hat noch jemand eine Idee ?
  Mit Zitat antworten Zitat