fix: redirect to error message on contact failure
This commit is contained in:
parent
00aed04181
commit
33c3b434d7
|
@ -46,12 +46,21 @@ public class ContactController : Controller
|
|||
StringValues message = form["message"];
|
||||
|
||||
await using SmtpSender sender = CreateSender();
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue