Some checks are pending
CI / Build og unit tests (push) Waiting to run
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
A PDF report for management and auditors (PDFsharp/MigraDoc, MIT, with the Inter font embedded): key figures, a plain-language summary, compliance controls backed by rules (met, not met, not measured), instances and the critical and high findings. Downloadable from the web UI (/rapporter) and mailed monthly by the agent with the PDF attached, once per month, across daylight saving changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
using System.Globalization;
|
|
using MimeKit;
|
|
using SQLInsight.Notifications;
|
|
|
|
namespace SQLInsight.Reports;
|
|
|
|
/// <summary>Sends the management report as a PDF attachment through the same SMTP server as notifications.</summary>
|
|
public static class ReportMailer
|
|
{
|
|
private static readonly CultureInfo Danish = CultureInfo.GetCultureInfo("da-DK");
|
|
|
|
public static MimeMessage Build(EmailOptions smtp, IEnumerable<string> recipients, ReportData data, string periodName)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(smtp);
|
|
ArgumentNullException.ThrowIfNull(recipients);
|
|
ArgumentNullException.ThrowIfNull(data);
|
|
var message = new MimeMessage();
|
|
message.From.Add(MailboxAddress.Parse(smtp.From));
|
|
foreach (var to in recipients)
|
|
{
|
|
message.To.Add(MailboxAddress.Parse(to));
|
|
}
|
|
|
|
message.Subject = $"SQLInsight: Driftsrapport for {data.Organization}, {periodName}";
|
|
var body = new BodyBuilder
|
|
{
|
|
TextBody = $"Driftsrapport for SQL Server, {periodName}.\n\n"
|
|
+ string.Join("\n", ManagementReport.SummarySentences(data).Select(s => "• " + s))
|
|
+ "\n\nDen fulde rapport er vedhæftet som PDF.\n\nSendt af SQLInsight Pro",
|
|
};
|
|
body.Attachments.Add($"driftsrapport-{data.From.ToString("yyyy-MM", CultureInfo.InvariantCulture)}.pdf", ManagementReport.Render(data), new ContentType("application", "pdf"));
|
|
message.Body = body.ToMessageBody();
|
|
return message;
|
|
}
|
|
|
|
public static string MonthName(DateTimeOffset firstOfMonth) => firstOfMonth.ToString("MMMM yyyy", Danish);
|
|
|
|
public static Task SendAsync(EmailOptions smtp, MimeMessage message, CancellationToken cancellationToken) =>
|
|
EmailChannel.SendMessageAsync(smtp, message, cancellationToken);
|
|
}
|