My console app needs to send HTML emails. I'd like to write the emails in HTML format in a Razor view and have the engine generate the email body content.
This means no controllers or requests. How could I go about this?
Razor View Engine is a markup syntax which helps us to write HTML and server-side code in web pages using C# or VB.Net. It is server-side markup language however it is not at all a programming language.
Open the integrated terminal. Change to the directory ( cd ) which will contain the project. The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder. The code command opens the RazorPagesMovie folder in the current instance of Visual Studio Code.
Build and run your code in Visual Studio To run the code, on the menu bar, choose Debug, Start without debugging. A console window opens and then runs your app. When you start a console app in Visual Studio, it runs your code, then prints "Press any key to continue . . ." to give you a chance to see the output.
There is an open source project which allows to use Razor as a general templating engine: it's called RazorEngine (the code in on GitHub)
A sample for the project's page:
string template = "Hello @Model.Name! Welcome to Razor!"; string result = Razor.Parse(template, new { Name = "World" });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With