Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm developing an LMS in which lot of emails are generated from the system at various stages. Currently this is done through a class in which the content of email is pre-defined during the development itself (which is not a good coding). The end user need a facility by which he can create Email templates (body) and common parameters (like student name, course etc) should be made available so that he will include it in the body, in the run mode the system will pick this template and send the mail.
I have seen similar facility in some of the web applications. Can any one help me on how to implement this. Thanks in advance.
Posted
Comments
Abdul Samad KP 20-Sep-14 9:08am    
Design a page with a dropdown and a textbox or html editor control and a save button. Load all the template types (various stages) to dropdown list, so the user can select the template type and enter the templates with predefined tags and save it.
Then in your class, before sending email load the template and replace the tags.
maksha 20-Sep-14 13:31pm    
Thanks for your reply. Your solution could be used at the second stage of my requirement. First I want to create the template for various stage through user input and secondly the same can be used in the application. In the first stage how do I save the template either to db / file (not just saving) I'm looking for a solution where by user can create a formatted template (as in any wordprocessor).

1 solution

That is a facility that a form provides. Not an Email template!

What you need to do is to create a simple form that has some basic fields like I am a student/teacher, I would like to choose [course] from your [institute]. These are the only things that will differ in each of the email. So you can design the HTML for that. Suppose the following,

HTML
<form method="post">
   <!-- Basic fields -->
   <!-- Name of the application -->
   Name <input type="text" name="name" />
   <!--  His type, student or a teacher-->
   I am a <select name="type">
             <option value="student">Student</option>
             <option value="teacher">Teacher</option>
          </select>
   <!-- Course code -->
   Course code <select name="course">
                  <option value="845">845</option>
                  <option value="846">846</option>
                  <option value="847">847</option>
               </select>
   <!-- Application that he will fill out -->
   Application <textarea name="application"></textarea>
   <!-- Input button -->
   <input type="submit" value="Submit" />
</form>


..this is enough. Now since you said that you're using ASP.NET (in the tags) I would use the C# code to provide the remaining template of the code that you will write to enable this feature.

C#
// variable initialization
var name = Request["name"];
var type = Request["type"];
var course = Request["course"];
var application = Request["application"];

// checking if the request was POST
if(IsPost) {
   // working out the EMAIL
   // you can add your own validations such as 
   // if name is not null or empty string
   if(name != "" && name != null) {
      WebMail.Send(to: "recipient_email@example.com",
                   subject: "Application recieved", 
                   // create the body of the email.
                   body: "Thanks for applying " + name + 
                         "\nYou applied as a " + type + 
                         " for the course code " + course +
                         " and your application was as \n" + application
                  );
   }
}


Once this is sent, it will contain the dynamic data from the user. You will need to design your HTML as to enable the user to select from some provided tools and options. Then use those values and populate the HTML email.

You can learn more on sending emails using ASP.NET, from this article. Sending Emails Easily Using ASP.NET Helpers[^]
 
Share this answer
 
v2
Comments
maksha 20-Sep-14 13:27pm    
Thanks for your detailed reply. Sorry I think I didn't conveyed the requirement correctly. I'm not looking for a form by which I can get the details. I want a form in which the user can create a email template and save it to the database, same will be used elsewhere in the system.
Afzaal Ahmad Zeeshan 20-Sep-14 14:18pm    
I guess that is probably beyond the scope of Q&A, that would be a topic of Article or something.
Member 12717133 3-Jul-17 9:36am    
@marksha, did you find a solution to your problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900