Implement mail service with configuration and settings management
This commit is contained in:
30
FoodsharingSiegen.Server/Pages/Settings.razor
Normal file
30
FoodsharingSiegen.Server/Pages/Settings.razor
Normal file
@@ -0,0 +1,30 @@
|
||||
@page "/settings"
|
||||
|
||||
@inherits FsBase
|
||||
|
||||
<PageTitle>Einstellungen - @AppSettings.Terms.Title</PageTitle>
|
||||
|
||||
<div style="width: 100%; max-width: 500px;">
|
||||
<h2>Einstellungen</h2>
|
||||
|
||||
<div class="card mt-3">
|
||||
<div class="card-header" style="padding: .5rem 0 0 1rem;"><h5>Mail Service</h5></div>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
<strong>SMTP Server:</strong> @AppSettings.Mail.Host<br />
|
||||
<strong>Port:</strong> @AppSettings.Mail.Port<br />
|
||||
<strong>SSL:</strong> @(AppSettings.Mail.UseSsl ? "Ja" : "Nein")<br />
|
||||
</p>
|
||||
<hr />
|
||||
<Fields Class="my-3">
|
||||
<Field ColumnSize="ColumnSize.Is12">
|
||||
<FieldLabel>Testmail-Empfänger</FieldLabel>
|
||||
<FieldBody>
|
||||
<TextEdit @bind-Text="TestMailReceiver" Placeholder="E-Mail Adresse"></TextEdit>
|
||||
</FieldBody>
|
||||
</Field>
|
||||
</Fields>
|
||||
<Button Color="Color.Primary" Clicked="SendTestMail">Testmail senden</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
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