Email Template Engine

I'm going to write a simple email manager for the site I'm working on (asp.net/c#); the site sends various emails, for example, when creating an account, news, some user actions, etc. This will create email templates with placeholders such as [$ FirstName], which will be replaced with actual values. Pretty standard stuff. I'm just wondering if anyone can advise the existing code - again, I need something very simple, without a lot of bells and, obviously, with the source code (and free)

Any ideas / comments would be greatly appreciated!

Thanks Andrew

+3
source share
4 answers

There are already several threads about this in the stack overflow, but I ended my own solution from various sentences.

I used this FormatWith extension method to take care of simple templates, and then I made a base base base class to take care of common tasks, for example, pulling the appropriate template and replacing all the necessary information, as well as providing the Send () method.

All the emails I need to send have their own subclass coming from the database and define unique things for them, such as TemplateText, BindingData, Recipients and Subject. Having each of them in its class makes them very easy to unit test according to the rest of the application.

, , , (, , Send()), , , . , , , .

IEmail email = new MyEmailClass();
email.Send();

: : HTML/Email- ASP.NET?

+5

. = {#} . , ( ), string.Format(template,param1,param2..)

. - , - , string.format .

Alison R , 3,5 . 3.5, FormatWith ( ), .

+1

ASP.NET, . ASP.NET, ( .. ..), ContentType ( HTML, )

, .

HttpWebRequest/HttpWebResponse WebClient, URL- . ASP.NET , .

- , RegEx ? , ( , , , escape- ), Match .

"getcha" RegEx - , , .

0

, : HTML, . , , .NET.

, HTML- (AKA, ) , ( : <% TAGNAME% > ), , -, , , HTML-. SMTP, .NET, . .

, . , !

0

Source: https://habr.com/ru/post/1733563/


All Articles