diff --git a/GmailTokenManager.cs b/GmailTokenManager.cs index ecd9bbc..7b8daba 100644 --- a/GmailTokenManager.cs +++ b/GmailTokenManager.cs @@ -1,5 +1,6 @@ using Google.Apis.Auth.OAuth2; using Google.Apis.Util.Store; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -25,23 +26,33 @@ public static class GmailTokenManager public static async Task ObtenerAccessTokenAsync(GmailConfig config) { var stream = new MemoryStream(config.ClientSecret); - - await _tokenSemaphore.WaitAsync(); - try + int i = 0; + do { - var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync( - GoogleClientSecrets.FromStream(stream).Secrets, - new[] { "https://mail.google.com/" }, - config.Usuario, - CancellationToken.None, - new FileDataStore(config.TokenFolder, true) - ); + i++; + await _tokenSemaphore.WaitAsync(); + try + { + var credencial = await GoogleWebAuthorizationBroker.AuthorizeAsync( + GoogleClientSecrets.FromStream(stream).Secrets, + new[] { "https://mail.google.com/" }, + config.Usuario, + CancellationToken.None, + new FileDataStore(config.TokenFolder, true) + ); - return await credencial.GetAccessTokenForRequestAsync(); - } - finally - { - _tokenSemaphore.Release(); + return await credencial.GetAccessTokenForRequestAsync(); + } + catch (Exception ex) + { + if (i > 1) throw new Exception(ex.Message,ex); + System.Threading.Thread.Sleep(5000); + } + finally + { + _tokenSemaphore.Release(); + } } + while (true); } } \ No newline at end of file diff --git a/tsGmail.csproj b/tsGmail.csproj index 912299b..537f50f 100644 --- a/tsGmail.csproj +++ b/tsGmail.csproj @@ -11,6 +11,7 @@ Tecnosis S.A Envío de correos con cuentas de gmail + - Version 1.0.2 Se introduce un reintento en la obtención de token - Version 1.0.1 2025-09-22 Corrección rutinas asyncronas - Version 1.0.0 2025-09-18 Primera versión