Implement mail service with configuration and settings management
This commit is contained in:
45
FoodsharingSiegen.Server/Pages/Settings.razor.cs
Normal file
45
FoodsharingSiegen.Server/Pages/Settings.razor.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using FoodsharingSiegen.Contracts.Helper;
|
||||
using FoodsharingSiegen.Server.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FoodsharingSiegen.Server.Pages
|
||||
{
|
||||
public partial class Settings
|
||||
{
|
||||
[Inject]
|
||||
public IMailService MailService { get; set; } = null!;
|
||||
|
||||
private string TestMailReceiver { get; set; } = string.Empty;
|
||||
|
||||
protected override async Task InitializeDataAsync()
|
||||
{
|
||||
if (!CurrentUser.IsAdmin())
|
||||
{
|
||||
NavigationManager.NavigateTo("/");
|
||||
return;
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task SendTestMail()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(TestMailReceiver))
|
||||
{
|
||||
await Notification.Error("Bitte eine Empfänger-Adresse angeben.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await MailService.SendEmailAsync(TestMailReceiver, "Testmail", "Dies ist eine Testmail.");
|
||||
await Notification.Success("Testmail versendet.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Notification.Error($"Fehler beim Senden: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user