using System.Net.Http.Json; using System.Text.Json.Serialization.Metadata; using CM.Authentication.Abstractions; namespace CM.TransactionalEmail; public class TransactionalEmailService(IHttpClientFactory httpClientFactory, IJwtTokenManagerService jwtTokenManagerService) { private readonly string _endpoint = "https://api.cakemail.dev"; private readonly HttpClient _httpClient = httpClientFactory.CreateClient(); public async Task SendEmailAsync(SendEmailOptions options, CancellationToken cancellationToken = default) { var endpoint = $"{_endpoint}/emails"; var token = await jwtTokenManagerService.GetTokenAsync(cancellationToken); _httpClient.SetJwtAccessToken(token); var request = new HttpRequestMessage(HttpMethod.Post, endpoint) { Content = JsonContent.Create(options, TransactionEmailJsonSerializerContext.Default.SendEmailOptions) }; var response = await _httpClient.SendAsync(request, cancellationToken); response.EnsureSuccessStatusCode(); } }