mirror of
https://github.com/bitwarden/server.git
synced 2025-02-14 01:31:24 +01:00
retry sendgrid send if fails
This commit is contained in:
parent
ef2e159b4e
commit
d56d3e01f0
@ -5,6 +5,8 @@ using SendGrid;
|
||||
using SendGrid.Helpers.Mail;
|
||||
using Bit.Core.Models.Mail;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
@ -61,6 +63,28 @@ namespace Bit.Core.Services
|
||||
sendGridMessage.SetBypassListManagement(bypass.GetValueOrDefault(false));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await SendAsync(sendGridMessage, false);
|
||||
}
|
||||
catch(HttpRequestException)
|
||||
{
|
||||
await SendAsync(sendGridMessage, true);
|
||||
}
|
||||
catch(WebException)
|
||||
{
|
||||
await SendAsync(sendGridMessage, true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendAsync(SendGridMessage sendGridMessage, bool retry)
|
||||
{
|
||||
if(retry)
|
||||
{
|
||||
// wait and try again
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
|
||||
await _client.SendEmailAsync(sendGridMessage);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user