fix: redirect to error message on contact failure

This commit is contained in:
Oliver Booth 2023-09-25 19:58:11 +01:00
parent 00aed04181
commit 33c3b434d7
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5
1 changed files with 15 additions and 6 deletions

View File

@ -46,12 +46,21 @@ public class ContactController : Controller
StringValues message = form["message"];
await using SmtpSender sender = CreateSender();
await sender.WriteEmail
.To("Oliver Booth", _destination.Get<string>())
.From(name, email)
.Subject($"[Contact via Website] {subject}")
.BodyText(message)
.SendAsync();
try
{
await sender.WriteEmail
.To("Oliver Booth", _destination.Get<string>())
.From(name, email)
.Subject($"[Contact via Website] {subject}")
.BodyText(message)
.SendAsync();
}
catch (Exception e)
{
_logger.LogError(e, "Failed to send email");
TempData["Success"] = false;
return RedirectToPage("/Contact/Result");
}
TempData["Success"] = true;
return RedirectToPage("/Contact/Result");