We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Email template in ASP.NET MVC

Hi, I have a problem in my application. I would like to create a functionality that will be resposible for creating text emails template. These emails will be send to application users. The main problem is about the data binding like FirstName, LastName etc. It is possible to do it? For this moment, my MVC app keeps all emails in application code and they are not editable from admin panel. What control should I use to allow edit emails body from admin panel?

Any ideas? Thanks for Your help

7 Replies

PM Pandiyaraj Muniyandi Syncfusion Team October 1, 2019 07:30 PM UTC

Hi Bart 
Greetings from Syncfusion support. 
We suggest you to use RichTextEditor component to edit your email body content at application end. 
Refer the below links 
Pandiyaraj M 

BA Bart October 1, 2019 09:16 PM UTC

Hi Pandiyaraj M, thanks for Your reply. I still have a brainstorm because I don't know how to do it.

My idea:
This is how e-mail could look in the admin panel for example:

Hi, @FirstName @LastName

and these @firstname 'properties' should be converted in the app code to real data from database. It is possible?


PM Pandiyaraj Muniyandi Syncfusion Team October 2, 2019 09:35 AM UTC

Hi Bart,  
Good day to you. 
In your application end to edit the email content, you need to set the content into RichTextEditor Value property. Before set the database content into RTE, you need do property binding from code behind in controller as follows 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
namespace WebApplication1.Controllers 
    public class HomeController : Controller 
        public ActionResult Index() 
            // Assume this firstName, lastName from database 
            var firstName = "John"; 
            var lastName = "Michael"; 
            // Bind fields content to RTE value property ViewBag emailContent varaible 
            ViewBag.emailContent = "

Hi " + @firstName + " " + @lastName + ",

Sample mail body



            return View(); 
We have prepared sample for your reference, get it from below link 
Pandiyaraj M 

BA Bart October 2, 2019 10:51 AM UTC

Hi Pandiyaraj M, thanks for reply and code, but I was thinking about in this case:

I don't need to render this binding data in richtexteditor.

Steps like this:

1. In admin panel I will set the content email body like:
"Hi @firstname @lastname. I am writing to you bla bla bla"
2. Save this content in the same form to the database
3. In data adapter I will be taking content from database and raplace these properties @firstname, @lastname the real data loading from another user data adapter.

If this way will be okey?


NP Narayanasamy Panneer Selvam Syncfusion Team October 3, 2019 12:44 PM UTC

Hi Bart, 
Thanks for your information. 
We have proceeded further based on the provided information. You can get content using data manager by sending request using the url property. Then, by using the executeQuery method of the data manager you can filter the results based on the required condition. This is demonstrated in the below sample code where data is fetched from a service URL and printed in the button click event, 
<button id="fetchdata">Fetch data</button> 
    $("#fetchdata").click(function () { 
        new ej.data.DataManager({ 
            url: "https://services.odata.org/V4/Northwind/Northwind.svc/Orders/", 
            adaptor: new ej.data.ODataV4Adaptor, 
            crossDomain: true 
        }).executeQuery(new ej.data.Query().where('OrderID', 'equal', 10258)).then((e) => { 
            alert("Hi " + e.result[0].CustomerID + ", Sample mail body Regards, John"); 
            // Here you can use the returned data as per your requirement 

Similarly, you can customize the request and use the response as per your requirement. You can find sample below for your reference, 
For more details on the data manager control you can refer the following documentation, 
Narayanasamy P. 

BA Bart October 10, 2019 10:15 AM UTC

Hi, thanks, You helped me. I have one more question about richtexteditor in the view file. Is it possible to render richtexteditor in foreach loop for any other email? The view will contain around 20 richtexteditors so that's why I'm asking.

NP Narayanasamy Panneer Selvam Syncfusion Team October 12, 2019 11:29 AM UTC

Hi Bart, 
Thanks for your update. 
Yes, you can render RTE using foreach loop as follows, 
    ViewBag.Title = "Home Page"; 
    ViewBag.items = new string[] { 
@foreach (var item in ViewBag.items) 
        @Html.EJS().RichTextEditor(item).Value("Hi " + item).Render() 
    <br /><br /> 
We have prepared sample to meet your requirement, get it from below link 
Kindly let us know if you need further assistance on this.

Narayanasamy P.

Live Chat Icon For mobile
Up arrow icon