Implement Plunk email sending service with HttpClient integration and DTO definition.
This commit is contained in:
@@ -9,7 +9,5 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
public void Configure(EntityTypeBuilder<User> entity)
|
||||
{
|
||||
entity.Property(e => e.Ininitals).HasMaxLength(5);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
9
API/Models/Outgoing/PlunkEmailDto.cs
Normal file
9
API/Models/Outgoing/PlunkEmailDto.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace API.Models.Outgoing;
|
||||
|
||||
public class PlunkEmailDto
|
||||
{
|
||||
public required string To { get; set; }
|
||||
public required string Subject { get; set; }
|
||||
public required string Body { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
@@ -68,9 +68,6 @@ app.UseHttpsRedirection();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
// Map Auth Endpoints
|
||||
app.MapIdentityApi<User>();
|
||||
|
||||
app.MapControllers();
|
||||
// Frontend Fallback
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user