Extract the email template into a partial view (so you could reuse it), then
you can render the partial view into a string in the controller action so you could use it as email body:
This method taken from Render a view as a string will allow you to render partial view into a string:
public string RenderRazorViewToString(string viewName, object model)
{
ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext,
viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View,
ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
return sw.GetStringBuilder().ToString();
}
}
In the controller action that should send an email you can do something like this:
public ActionResult SendEmail(SomeModel model)
{
//generate a model for an email:
var emailModel = ....;
//assuming that _EmailTemplate.cshtml is a partial view that contains the email template
var emailBody = this.RenderRazorViewToString("_EmailTemplate",emailModel);
//send the email here...
}