Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Faisal Mushtaq 19 posts 119 karma points
    Feb 04, 2015 @ 12:11
    Faisal Mushtaq
    0

    Configurable Email Template

    Can user create configurable body of email in umbraco 7.2. I am creating a member registration form using partial view and macro. On successful registeration, I have to send email and I have to put some registration form fields on email body. Can user create configurable template using backoffice site?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 04, 2015 @ 17:17
    Alex Skrypnyk
    0

    Hi Faisal,

    Welcome to Umbraco Comunity.

    You can use richTextEditor or some razor template for that.

    We are using razor view now, we are creating view like that :

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    <!DOCTYPE html>
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Email</title>
    </head>
    <body>
         <div>
            @Model.FirstName
        </div>
         <div>
            @Model.Surname
        </div>
        <div>
            @Model.Message
        </div>
    </body>
    </html>
    

    In the contact Surface controller we are creating ContactModel and fill data, after that we are rendering view in the code like that :

    protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action");

        ViewData.Model = model;
    
        using (var sw = new StringWriter())
        {
            var viewResult = ViewEngines.Engines.FindView(ControllerContext, viewName, "");
            var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
            viewResult.View.Render(viewContext, sw);
    
            return sw.GetStringBuilder().ToString();
        }
    }
    

    And send that html code via email.

    Thanks, Alexander

Please Sign in or register to post replies

Write your reply to:

Draft