How to write a Customized HTML Email in C# .NET dll (dynamic link library) using razor engine
Aug 23, 2017 · 1 min read
writing an HTML Email is dll project is different from writing it in MVC project.
We need to write HTML Email code using razor engine.
Razor engine is different from Razor view, which we are familiar in ASP.NET world.
In the executable project or service project where you gonna refer this dll project , write in App.config under arguments section
<arguments>
<add name="EmailBody" value="<html>
<body>
<p>
@Model.Name is going to
@Model.Country*********
</p>
</body>
</html>" />
<arguments/>Note: html regular<> tags don’t work in app.config
write following in your dll project c# class
template = config[“Template”].Value;//key need to be unique , the fallowing code line will create unique template keytemplateKey = subject + from + DateTime.UtcNow.ToString(“yyyy-MM-dd hh.mm.ss.ffffff”);string EmailBody= Engine.Razor.RunCompile(template, templateKey, null, model);// we can pass any object in place of model which will acts as model in App.config file mentioned above
Now we can send this ‘EmailBody’ using your respective email client such as SMTP client
Note: you need to get RazorEngine referred in your dll project. for more refer razor engine official documentation .