forked from leaderboardsgg/leaderboard-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Brevo Rest API (leaderboardsgg#218)
* Add brevo csharp client. * Add Brevo options. * Add Brevo service. * Replace EmailSender with BrevoService. * Update TestApiFactory to mock Brevo. * Mark EmailSender as Obsolete. * formatting
- Loading branch information
Showing
9 changed files
with
64 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FluentValidation; | ||
|
||
namespace LeaderboardBackend.Services; | ||
|
||
public class BrevoOptions | ||
{ | ||
public const string KEY = "Brevo"; | ||
public string ApiKey { get; set; } = string.Empty; | ||
public required string SenderName { get; set; } | ||
public required string SenderEmail { get; set; } | ||
} | ||
|
||
public class BrevoOptionsValidator : AbstractValidator<BrevoOptions> | ||
{ | ||
public BrevoOptionsValidator() | ||
{ | ||
RuleFor(x => x.SenderName).NotEmpty(); | ||
RuleFor(x => x.SenderEmail).EmailAddress(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using brevo_csharp.Api; | ||
using brevo_csharp.Model; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace LeaderboardBackend.Services; | ||
|
||
public class BrevoService(IOptions<BrevoOptions> options, ILogger<BrevoService> logger) : IEmailSender | ||
{ | ||
private readonly TransactionalEmailsApi _transactionalEmailsApi = new(); | ||
private readonly SendSmtpEmailSender _smtpEmailSender = new(options.Value.SenderName, options.Value.SenderEmail); | ||
|
||
public async System.Threading.Tasks.Task EnqueueEmailAsync(string recipientAddress, string subject, string htmlMessage) | ||
{ | ||
SendSmtpEmail email = new(_smtpEmailSender, [new(recipientAddress)], null, null, htmlMessage, null, subject); | ||
CreateSmtpEmail result = await _transactionalEmailsApi.SendTransacEmailAsync(email); | ||
logger.LogInformation("Email sent with id {Id}", result.MessageId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
}, | ||
"EnvPath": ".env", | ||
"AllowedHosts": "*", | ||
"EmailSender": { | ||
"Brevo": { | ||
"SenderName": "Leaderboards.gg", | ||
"SenderAddress": "[email protected]" | ||
"SenderEmail": "[email protected]" | ||
}, | ||
"Feature": { | ||
"AccountRecovery": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters