Implement Plunk email sending service with HttpClient integration and DTO definition.

This commit is contained in:
2026-01-25 13:43:25 +01:00
parent ba2a455a2b
commit d1a72876d2
4 changed files with 38 additions and 9 deletions

View File

@@ -1,11 +1,36 @@
using Microsoft.AspNetCore.Identity.UI.Services;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using API.Models.Outgoing;
using Microsoft.AspNetCore.Identity.UI.Services;
namespace API.Services;
public class PlunkEmailSender : IEmailSender
public class PlunkEmailSender(HttpClient httpClient, string plunkSecretKey) : IEmailSender
{
public Task SendEmailAsync(string email, string subject, string htmlMessage)
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
{
throw new NotImplementedException();
var requestBody = new PlunkEmailDto()
{
To = email,
Subject = subject,
Body = htmlMessage
};
var jsonContent = new StringContent(
JsonSerializer.Serialize(requestBody),
Encoding.UTF8,
"application/json"
);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", plunkSecretKey);
var response = await httpClient.PostAsync("https://api.useplunk.com/v1/send", jsonContent);
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync();
throw new Exception($"Fehler beim Senden der E-Mail über Plunk: {error}");
}
}
}