Use HTML Body To Prevent Spam Flags

This commit is contained in:
Alan Moon 2025-07-26 23:32:42 -07:00 committed by Alan Moon
parent 503653e951
commit 08fb330de3
2 changed files with 33 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization; using Azure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers;
@ -120,13 +121,32 @@ namespace qtc_api.Controllers
return Ok(response); return Ok(response);
} }
[HttpPost("resend-email")]
public async Task<ActionResult<ServiceResponse<bool>>> ResendVerificationEmail(string email)
{
var user = await _userService.GetUserByEmail(email);
if (user != null && user.Success && user.Data != null)
{
var confirmationToken = _tokenService.GenerateEmailConfirmationToken(user.Data);
var confirmationUrl = $"{Request.Scheme}://{Request.Host}/api/auth/verify-email?token={confirmationToken.Data}";
await _emailService.SendConfirmationEmail(user.Data.Email, user.Data.Username, confirmationUrl);
return Ok(new ServiceResponse<bool> { Success = true, Data = true });
}
return Ok(new ServiceResponse<bool> { Success = false });
}
[HttpGet("verify-email")] [HttpGet("verify-email")]
public async Task<ActionResult<string>> VerifyEmail(string token) public async Task<ActionResult<string>> VerifyEmail(string token)
{ {
try try
{ {
var handler = new JwtSecurityTokenHandler(); var handler = new JwtSecurityTokenHandler()
handler.InboundClaimTypeMap = new Dictionary<string, string>(); {
InboundClaimTypeMap = new Dictionary<string, string>()
};
var jwt = handler.ReadJwtToken(token); var jwt = handler.ReadJwtToken(token);

View File

@ -38,16 +38,17 @@ namespace qtc_api.Services.EmailService
// build confirmation email body // build confirmation email body
StringBuilder emailBody = new(); StringBuilder emailBody = new();
emailBody.AppendLine($"Hello {name},"); emailBody.AppendLine($"<h1>Hello {name},</h1>");
emailBody.AppendLine(); emailBody.AppendLine("<p>Your receiving this message because you made a QtC.NET Account on a server that requires email confirmation.<br>");
emailBody.AppendLine($"Your receiving this message because you made a QtC.NET Account on a server that requires email confirmation."); emailBody.AppendLine(@$"You can confirm your account by clicking <a href=""{confirmUrl}"">here.</a><br>");
emailBody.AppendLine(); emailBody.AppendLine("NOTE: This Link Is Only Valid For 24 Hours.<br><br>");
emailBody.AppendLine($"You can confirm your email by clicking here - {confirmUrl}"); emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.</p>");
emailBody.AppendLine();
emailBody.AppendLine("If you did not create a QtC.NET account on any server, you may simply ignore this email.");
// create new client // create new client
using var client = new SmtpClient(); using var client = new SmtpClient()
{
RequireTLS = true
};
// connect and authenticate // connect and authenticate
await client.ConnectAsync(host, 587); await client.ConnectAsync(host, 587);
@ -59,7 +60,7 @@ namespace qtc_api.Services.EmailService
message.From.Add(new MailboxAddress("QtC.NET Server", senderAddress)); message.From.Add(new MailboxAddress("QtC.NET Server", senderAddress));
message.Subject = emailSubject; message.Subject = emailSubject;
message.Body = new TextPart(MimeKit.Text.TextFormat.Plain) message.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{ {
Text = emailBody.ToString() Text = emailBody.ToString()
}; };