Configure Danish response emails and optimize survey email template for inbox delivery

This commit is contained in:
Qaisyousuf 2025-08-05 17:59:13 +02:00
parent 24812a77fa
commit 13bf203fe4
2 changed files with 127 additions and 70 deletions

View file

@ -2,11 +2,6 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Model; using Model;
using Services.Interaces; using Services.Interaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services.Implemnetation namespace Services.Implemnetation
{ {

View file

@ -113,7 +113,6 @@ namespace Web.Controllers
{ {
bool hasSubmitted = _context.Responses.Any(r => r.QuestionnaireId == questionnaire.Id && r.UserEmail == questionnaire.Email); bool hasSubmitted = _context.Responses.Any(r => r.QuestionnaireId == questionnaire.Id && r.UserEmail == questionnaire.Email);
var cetZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); var cetZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
var cetTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cetZone); var cetTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, cetZone);
var response = new Response var response = new Response
@ -125,89 +124,152 @@ namespace Web.Controllers
ResponseDetails = questionnaire.Questions.Select(q => new ResponseDetail ResponseDetails = questionnaire.Questions.Select(q => new ResponseDetail
{ {
QuestionId = q.Id, QuestionId = q.Id,
QuestionType=q.Type, QuestionType = q.Type,
// Handle TextResponse based on question type TextResponse = (q.Type == QuestionType.Open_ended || q.Type == QuestionType.Text || q.Type == QuestionType.Slider)
TextResponse = (q.Type == QuestionType.Open_ended || q.Type == QuestionType.Text || q.Type==QuestionType.Slider) ? string.Join(" ", q.SelectedText)
? string.Join(" ", q.SelectedText) // Ensure SelectedText is appropriately used based on question type
: null, : null,
ResponseAnswers = q.SelectedAnswerIds ResponseAnswers = q.SelectedAnswerIds
.Select(aid => new ResponseAnswer { AnswerId = aid }) .Select(aid => new ResponseAnswer { AnswerId = aid })
.ToList() // Ensure that the list is initialized correctly .ToList()
}).ToList() }).ToList()
}; };
_context.Responses.Add(response); _context.Responses.Add(response);
_context.SaveChanges(); _context.SaveChanges();
var subject = $"Thank You for Your Feedback, {questionnaire.UserName}!";
// ✅ PERSONAL SUBJECT LINE (like survey invitation)
var subject = $"Tak for din besvarelse, {questionnaire.UserName}";
var toEmail = questionnaire.Email; var toEmail = questionnaire.Email;
string emailBody = $@"
<html> // ✅ SIMPLE, PROFESSIONAL EMAIL BODY
<head> string emailBody = GenerateThankYouEmailBody(questionnaire.UserName);
// ✅ SAME HEADERS AS SURVEY INVITATION (Primary Inbox Optimized)
var emailSend = new EmailToSend(toEmail, subject, emailBody)
{
Headers = new Dictionary<string, string>
{
{ "X-Priority", "1" },
{ "Importance", "High" },
{ "List-Unsubscribe", "<mailto:kontakt@nvkn.dk?subject=Unsubscribe>" },
{ "List-Unsubscribe-Post", "List-Unsubscribe=One-Click" },
{ "X-Microsoft-Classification", "Personal" }
}
};
_emailServices.SendConfirmationEmailAsync(emailSend);
TempData["UserName"] = questionnaire.UserName;
_hubContext.Clients.All.SendAsync("ReceiveNotification", questionnaire.UserName, questionnaire.Email);
return RedirectToAction(nameof(ThankYou));
}
// ✅ COMPLETE CORRECTED METHOD: Danish Thank You Email Body
private static string GenerateThankYouEmailBody(string userName)
{
return $@"
<!DOCTYPE html>
<html lang='da'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Tak for dit svar</title>
<style> <style>
/* Inline CSS styles */
body {{ body {{
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1.4;
color: #333;
background-color: #ffffff;
margin: 0;
padding: 0;
}} }}
.container {{ .container {{
max-width: 600px; max-width: 600px;
margin: 0 auto; margin: 0 auto;
padding: 20px; padding: 20px;
border: 0.5px solid #ccc; background-color: #ffffff;
border-radius: 5px;
background-color: #f9f9f9;
}} }}
.button {{
display: inline-block; .header {{
padding: 10px 20px; border-bottom: 1px solid #ccc;
background-color: #007bff; padding-bottom: 10px;
color: #ffffff; margin-bottom: 20px;
}}
.content {{
margin-bottom: 20px;
}}
.content p {{
margin: 10px 0;
}}
.signature {{
margin-top: 20px;
padding-top: 15px;
border-top: 1px solid #ccc;
}}
.company-info {{
font-size: 12px;
color: #666;
margin-top: 15px;
}}
.footer {{
border-top: 1px solid #ccc;
padding-top: 15px;
margin-top: 20px;
font-size: 12px;
color: #666;
}}
.link {{
color: #0066cc;
text-decoration: none; text-decoration: none;
border-radius: 4px;
}}
.button:hover {{
background-color: #0056b3;
}} }}
</style> </style>
</head> </head>
<body> <body>
<div class='container'> <div class='container'>
<h4>Hey {questionnaire.UserName.ToUpper()},</h4> <div class='header'>
<h5>{subject}</h5> <strong>Nærværskonsulenterne ApS</strong>
<p><strong>Thank you so much for taking the time to provide us with your valuable feedback!</strong></p> </div>
<p>If you have any more thoughts to share or need assistance, please don't hesitate to reach out. You can email us directly at seo@seosoft.dk, and we'll be more than happy to help.</p> <div class='content'>
<p>Kære {userName},</p>
<p>Thank you once again, {questionnaire.UserName}, for helping us make SeoSoft ApS even better. We truly value your support and participation.</p> <p><strong>Vi har modtaget din besvarelse. Tak for din tid, {userName}.</strong></p>
<p>Har du spørgsmål, er du velkommen til at kontakte os <a href='mailto:kontakt@nvkn.dk' class='link'>kontakt@nvkn.dk</a>.</p>
</div>
<br> <div class='signature'>
<p><strong>Søren Eggert Lundsteen Olsen</strong><br> <p>Med venlig hilsen,<br/>
Seosoft ApS<br> <strong>Nærværskonsulenterne ApS</strong></p>
<hr> </div>
Hovedgaden 3
Jordrup<br> <div class='company-info'>
Kolding 6064<br> <p><strong>Nærværskonsulenterne ApS</strong><br/>
Denmark</p> Brødemosevej 24A<br/>
3300 Frederiksværk<br/>
Danmark</p>
<br/>
</div> </div>
</body>
</html>";
// Call the SendConfirmationEmailAsync method to send the email
var emailSend = new EmailToSend(toEmail, subject, emailBody);
_emailServices.SendConfirmationEmailAsync(emailSend);
TempData["UserName"] = questionnaire.UserName;
_hubContext.Clients.All.SendAsync("ReceiveNotification", questionnaire.UserName, questionnaire.Email);
return RedirectToAction(nameof(ThankYou));
<div class='footer'>
<p>Ønsker du ikke længere at modtage disse emails?
<a href='mailto:kontakt@nvkn.dk?subject=Afmeld%20fra%20emails' style='color: #666;'>Klik her for at afmelde</a></p>
</div>
</div>
</body>
</html>";
} }
[HttpGet] [HttpGet]