I am trying to create template application. In which I am sending umbraco content template in email. But it seems Umbraco templates are not responsive with in email applications.
Can any body suggest how should I design template in Umbraco for email content.
Not sure i'm getting it right, but here goes. If you wan' to be able to create views in Umbraco backend and render them as (html)string for sending as email then you could do like so (note that this is not bound to any Umbraco stuff, so you could do the same from any other asp.net app):
Create a model that hold data you need:
public class EmailViewModel
{
public string Recipient { get; set; }
public string Sender { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public string Signature { get; set; }
...
}
Create a controller that will return a view populated with your model
public class DefaultEmailController : Controller
{
public ActionResult Index(EmailViewModel model)
{
return View(model);
}
}
Create one more controller - we will need this to satisfy ControllerContext in below method
//
public class EmptyController : ControllerBase
{
protected override void ExecuteCore() { }
}
Create the method that will render the view to string
public static class EmailHelper
{
public static string RenderViewToString(string controllerName, string viewName, object viewData)
{
var context = HttpContext.Current;
var contextBase = new HttpContextWrapper(context);
var routeData = new RouteData();
routeData.Values.Add("controller", controllerName);
var controllerContext = new ControllerContext(contextBase, routeData, new EmptyController());
var razorViewEngine = new RazorViewEngine();
var razorViewResult = razorViewEngine.FindView(controllerContext, viewName, "", false);
var writer = new StringWriter();
var viewContext = new ViewContext(controllerContext, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
razorViewResult.View.Render(viewContext, writer);
return writer.ToString();
}}
Email template
I am trying to create template application. In which I am sending umbraco content template in email. But it seems Umbraco templates are not responsive with in email applications.
Can any body suggest how should I design template in Umbraco for email content.
Not sure i'm getting it right, but here goes. If you wan' to be able to create views in Umbraco backend and render them as (html)string for sending as email then you could do like so (note that this is not bound to any Umbraco stuff, so you could do the same from any other asp.net app):
Create a model that hold data you need:
Create a controller that will return a view populated with your model
Create one more controller - we will need this to satisfy ControllerContext in below method // public class EmptyController : ControllerBase { protected override void ExecuteCore() { } }
Create the method that will render the view to string
Now we need a view that will consume our model:
Ok, lets create mail:
// casper
Thank you! This post was a lifesaver ... Have been struggeling with this for days.
I can recommend PerplexMail package, it's make sending email and template managing very easy
is working on a reply...