S
S
Sergey Nizhny Novgorod2018-04-09 16:39:33
ASP.NET
Sergey Nizhny Novgorod, 2018-04-09 16:39:33

How to send email messages with html template from asp.net core?

Hello everyone
There are several ready-made html-inline templates in which you need to insert data and send it to users. How can this be done with asp.net core mvc?
Now sending letters in it is carried out using mimeKit, which offers a bodybuilder to form a message. I did not see any ready-made solutions for loading templates there. As a result, the only thing that comes to mind is to somehow drive the entire template string, then drive it into this builder, and then insert the data using the usual formatting. Those. not a very cool way.
What is the right way to send messages now?
Ps Naturally, you can take some kind of e-mail service, where to download all the templates, and just pull them by api, but you want it natively.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor P., 2018-04-19
@Terras

If asp.net core, then you can store templates in cshtml with the transfer of typed models for letters and everything related.
If you pull directly manually, then you need something like:

var path = "...";
var text = File.ReadAllText(path);
var param = new Dictionary<string, string>
{
 param1 = "koko"
};

var templateService = new TemplateService();//RazorEngine.Templating
var emailHtmlBody = templateService.Parse(templateText, param, null, null);

Although they say that TemplateService is deprecated, you need to use something from RazorEngineService

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question