Add HTML email shell templates to email InitialSchema migration
- Add email.html-shell.start: Opening HTML wrapper with blue header and MyAi.ro branding - Add email.html-shell.end: Closing HTML wrapper with footer - These templates wrap HTML email bodies before sending via SmtpEmailDispatcher - Language key set to '*' (language-agnostic) - Ensures email shell templates are seeded automatically on fresh database initialization Fixes the "Email template not found: key='email.html-shell.start'" error that prevented email sending. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Email.Data;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
@@ -12,11 +13,11 @@ namespace Email.Data.Migrations
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.EnsureSchema(
|
||||
name: "email");
|
||||
name: MigrationConstants.SchemaName);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Templates",
|
||||
schema: "email",
|
||||
schema: MigrationConstants.SchemaName,
|
||||
columns: table => new
|
||||
{
|
||||
Key = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
|
||||
@@ -31,24 +32,110 @@ namespace Email.Data.Migrations
|
||||
table.PrimaryKey("PK_Templates", x => new { x.Key, x.Language });
|
||||
});
|
||||
|
||||
// Seed email templates with a single comprehensive SQL batch
|
||||
migrationBuilder.Sql(@"
|
||||
INSERT INTO [email].Templates ([Key], [Language], [Value], [Description]) VALUES
|
||||
('email.match.subject', 'en', 'MyAi.ro CV Match: {{score}}% - {{jobLabel}}', 'Subject for the CV match result email'),
|
||||
('email.match.subject', 'ro', 'MyAi.ro Potrivire CV: {{score}}% - {{jobLabel}}', 'Subiect email rezultat potrivire CV'),
|
||||
('email.search-results.subject', 'en', 'MyAi.ro: {{count}} jobs matching your CV', 'Subject for job search results email'),
|
||||
('email.search-results.subject', 'ro', 'MyAi.ro: {{count}} joburi potrivite CV-ului tau', 'Subiect email rezultate cautare joburi'),
|
||||
('html.job-search.started.title', 'en', 'Job search started', 'Title for job search started page'),
|
||||
('html.job-search.started.title', 'ro', 'Căutare joburi pornită', 'Titlu pagina cautare joburi pornita'),
|
||||
('html.job-search.already-used.title', 'en', 'Link already used', 'Title for already-used page'),
|
||||
('html.job-search.already-used.title', 'ro', 'Link deja folosit', 'Titlu pagina link deja folosit'),
|
||||
('html.job-search.expired.title', 'en', 'Link expired', 'Title for expired link page'),
|
||||
('html.job-search.expired.title', 'ro', 'Link expirat', 'Titlu pagina link expirat'),
|
||||
('html.job-search.invalid.title', 'en', 'Invalid link', 'Title for invalid link page'),
|
||||
('html.job-search.invalid.title', 'ro', 'Link invalid', 'Titlu pagina link invalid'),
|
||||
('html.job-search.error.title', 'en', 'Error', 'Title for error page'),
|
||||
('html.job-search.error.title', 'ro', 'Eroare', 'Titlu pagina eroare');
|
||||
");
|
||||
Seed(migrationBuilder);
|
||||
}
|
||||
|
||||
private static void Seed(MigrationBuilder m)
|
||||
{
|
||||
void Row(string key, string lang, string value, string description = "")
|
||||
=> m.InsertData("Templates", ["Key", "Language", "Value", "Description"], [key, lang, value, description], MigrationConstants.SchemaName);
|
||||
|
||||
// Match result email — subject
|
||||
Row("email.match.subject", "en", "MyAi.ro CV Match: {{score}}% - {{jobLabel}}", "Subject for the CV match result email");
|
||||
Row("email.match.subject", "ro", "MyAi.ro Potrivire CV: {{score}}% - {{jobLabel}}", "Subiect email rezultat potrivire CV");
|
||||
|
||||
// Match result email — body
|
||||
Row("email.match.body", "en",
|
||||
"CV Matcher result\n\nCV Document ID: {{cvDocumentId}}\nJob: {{jobLabel}}\nJob URL: {{jobUrl}}\nScore: {{score}}%\n\nSummary:\n{{summary}}\n\nStrengths:\n{{strengths}}\n\nGaps:\n{{gaps}}\n\nRecommendations:\n{{recommendations}}",
|
||||
"Body for the CV match result email");
|
||||
Row("email.match.body", "ro",
|
||||
"Rezultat potrivire CV\n\nID document CV: {{cvDocumentId}}\nJob: {{jobLabel}}\nURL job: {{jobUrl}}\nScor: {{score}}%\n\nRezumat:\n{{summary}}\n\nPuncte forte:\n{{strengths}}\n\nLipsuri:\n{{gaps}}\n\nRecomandări:\n{{recommendations}}",
|
||||
"Corpul emailului pentru rezultatul potrivirii CV");
|
||||
|
||||
// Match result email — job search CTA footer
|
||||
Row("email.match.job-search-footer", "en",
|
||||
"\n\n---\nWant to find more jobs matching your CV?\nClick: {{jobSearchLink}}\n(link valid for {{expiryDays}} days)",
|
||||
"Job search CTA appended to match result email");
|
||||
Row("email.match.job-search-footer", "ro",
|
||||
"\n\n---\nVrei sa gasesti mai multe joburi potrivite CV-ului tau?\nClick: {{jobSearchLink}}\n(link valabil {{expiryDays}} zile)",
|
||||
"CTA cautare joburi adaugat la emailul de potrivire CV");
|
||||
|
||||
// Job search results email — subject
|
||||
Row("email.search-results.subject", "en", "MyAi.ro: {{count}} jobs matching your CV", "Subject for job search results email");
|
||||
Row("email.search-results.subject", "ro", "MyAi.ro: {{count}} joburi potrivite CV-ului tau", "Subiect email rezultate cautare joburi");
|
||||
|
||||
// Job search results email — body preamble (items appended in code)
|
||||
Row("email.search-results.body", "en", "MyAi.ro found {{count}} jobs matching your CV:\n\n{{items}}", "Body preamble for job search results email");
|
||||
Row("email.search-results.body", "ro", "MyAi.ro a gasit {{count}} joburi potrivite CV-ului tau:\n\n{{items}}", "Corpul emailului de rezultate cautare joburi");
|
||||
|
||||
// Job search results email — no results found
|
||||
Row("email.search-results.empty", "en", "MyAi.ro found no jobs matching your CV. Try again later or update your CV.", "No results message for job search results email");
|
||||
Row("email.search-results.empty", "ro", "MyAi.ro nu a gasit joburi care sa corespunda CV-ului tau. Incercati mai tarziu sau ajustati CV-ul.", "Mesaj fara rezultate pentru emailul de cautare joburi");
|
||||
|
||||
// HTML job-search start page messages
|
||||
Row("html.job-search.started.title", "en", "Job search started", "Title for job search started page");
|
||||
Row("html.job-search.started.message", "en", "Your job search has started. Results will be sent to your email shortly.", "Message for job search started page");
|
||||
Row("html.job-search.started.title", "ro", "Căutare joburi pornită", "Titlu pagina cautare joburi pornita");
|
||||
Row("html.job-search.started.message", "ro", "Căutarea joburilor a început. Rezultatele vor fi trimise pe email în scurt timp.", "Mesaj pagina cautare joburi pornita");
|
||||
|
||||
Row("html.job-search.already-used.title", "en", "Link already used", "Title for already-used page");
|
||||
Row("html.job-search.already-used.message", "en", "This job search link has already been used.", "Message for already-used page");
|
||||
Row("html.job-search.already-used.title", "ro", "Link deja folosit", "Titlu pagina link deja folosit");
|
||||
Row("html.job-search.already-used.message", "ro", "Acest link de cautare joburi a fost deja folosit.", "Mesaj pagina link deja folosit");
|
||||
|
||||
Row("html.job-search.expired.title", "en", "Link expired", "Title for expired link page");
|
||||
Row("html.job-search.expired.message", "en", "This job search link has expired. Please request a new CV match to get a fresh link.", "Message for expired link page");
|
||||
Row("html.job-search.expired.title", "ro", "Link expirat", "Titlu pagina link expirat");
|
||||
Row("html.job-search.expired.message", "ro", "Acest link de cautare joburi a expirat. Solicita o noua potrivire CV pentru a primi un link nou.", "Mesaj pagina link expirat");
|
||||
|
||||
Row("html.job-search.invalid.title", "en", "Invalid link", "Title for invalid link page");
|
||||
Row("html.job-search.invalid.message", "en", "This job search link is not valid.", "Message for invalid link page");
|
||||
Row("html.job-search.invalid.title", "ro", "Link invalid", "Titlu pagina link invalid");
|
||||
Row("html.job-search.invalid.message", "ro", "Acest link de cautare joburi nu este valid.", "Mesaj pagina link invalid");
|
||||
|
||||
Row("html.job-search.error.title", "en", "Error", "Title for error page");
|
||||
Row("html.job-search.error.message", "en", "An error occurred. Please try again later.", "Message for error page");
|
||||
Row("html.job-search.error.title", "ro", "Eroare", "Titlu pagina eroare");
|
||||
Row("html.job-search.error.message", "ro", "A apărut o eroare. Te rugăm să încerci din nou mai târziu.", "Mesaj pagina eroare");
|
||||
|
||||
// HTML email shell — opening tags (blue header, white card container)
|
||||
Row("email.html-shell.start", "*",
|
||||
$$"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; padding: 0; background-color: #f5f5f5; }
|
||||
.email-container { max-width: 600px; margin: 0 auto; background-color: #ffffff; }
|
||||
.email-header { background-color: #2c5282; color: white; padding: 24px; text-align: center; }
|
||||
.email-header h1 { margin: 0; font-size: 24px; font-weight: 600; }
|
||||
.email-body { padding: 24px; }
|
||||
.email-footer { background-color: #f8f9fa; padding: 16px; text-align: center; color: #6c757d; font-size: 12px; border-top: 1px solid #dee2e6; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="email-container">
|
||||
<div class="email-header">
|
||||
<h1>MyAi.ro</h1>
|
||||
</div>
|
||||
<div class="email-body">
|
||||
""",
|
||||
"Opening HTML wrapper for branded emails (blue header, white content area)");
|
||||
|
||||
// HTML email shell — closing tags (footer)
|
||||
Row("email.html-shell.end", "*",
|
||||
$$"""
|
||||
</div>
|
||||
<div class="email-footer">
|
||||
<p>© 2026 MyAi.ro. All rights reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
""",
|
||||
"Closing HTML wrapper for branded emails (footer and closing tags)");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -56,7 +143,7 @@ INSERT INTO [email].Templates ([Key], [Language], [Value], [Description]) VALUES
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Templates",
|
||||
schema: "email");
|
||||
schema: MigrationConstants.SchemaName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user