41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using BlazorTemplater;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NejCommon.Services.Email;
|
|
using System.Net.Mail;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace NejCommon.Emails
|
|
{
|
|
public abstract class EmailBase<T1, T2> : ComponentBase where T1 : EmailBase<T1, T2>
|
|
{
|
|
public static string _css = "";
|
|
public static string GetCss()
|
|
{
|
|
if (_css == "")
|
|
_css = File.ReadAllText(Path.Join(AppContext.BaseDirectory, "NejCommon/Emails/wwwroot/output.css"));
|
|
|
|
return _css;
|
|
}
|
|
|
|
|
|
[Parameter, EditorRequired]
|
|
public T2 Data { get; set; } = default!;
|
|
|
|
public static async Task<string> GetHTML(T2 dat)
|
|
{
|
|
string html = new ComponentRenderer<T1>().Set(x => x.Data, dat).Render();
|
|
var result = PreMailer.Net.PreMailer.MoveCssInline(html, css: GetCss());
|
|
|
|
return result.Html;
|
|
}
|
|
|
|
public virtual string GetSubject()
|
|
{
|
|
return "DEV: " + this.ToString();
|
|
}
|
|
|
|
public virtual List<Attachment> GetAttachments() => new List<Attachment>();
|
|
}
|
|
}
|