mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 19:14:32 -05: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 SendGrid.Helpers.Mail;
|
||||||
using Bit.Core.Models.Mail;
|
using Bit.Core.Models.Mail;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -61,6 +63,28 @@ namespace Bit.Core.Services
|
|||||||
sendGridMessage.SetBypassListManagement(bypass.GetValueOrDefault(false));
|
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);
|
await _client.SendEmailAsync(sendGridMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user