using Application.Abstractions.Messaging.Email; using SharedKernel; using Application.Abstractions.Messaging; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Options; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Admin.Pages.Config.Test { public class EmailModel(IMediator mediator, IOptions options, IMailService mailService) : PageModel { public readonly AppSettings Settings = options.Value; [BindProperty] [MaxLength(256)] [DataType(DataType.EmailAddress)] [DisplayName("To Address")] public string? ToAddress { get; set; } [BindProperty] public InputModel Input { get; set; } = new(); public async Task OnGetAsync(CancellationToken ct) { var config = await mediator.Send(new GetConfig.Query(), ct); if (config is not null) { Input = InputModel.From(config); } } public async Task OnPostAsync(CancellationToken ct) { if (!ModelState.IsValid) { return Page(); } await mailService.SendAsync( new SendData( ToAddress: ToAddress!, Subject: $"[TEST] SMTP ??? ?? ??? - {DateTime.Now:yyyy-MM-dd HH:mm:ss}", MessageHtml: $"""

??? ??

""", MessageText: $"TEST MAIL\nFrom={Settings.SMTP.FromEmail}\nTo={ToAddress}\nHost={Settings.SMTP.Host}:{Settings.SMTP.Port}\nTLS={Settings.SMTP.UseStartTls}" ), ct ); TempData["SuccessMessage"] = "??? ???? ??????."; return RedirectToPage(); } public sealed class InputModel { public UpdateConfig.Request.BasicConfigDto Basic { get; set; } = new(); public static InputModel From(GetConfig.Response config) { var req = UpdateConfig.Request.From(config); return new() { Basic = req.Basic }; } } } }