Saeid
Saeid

Reputation: 2046

Edit Email with Dynamic fields

My website has automatic email to users and there is some dynamic fields in email text. I mean, it automatically extract name family and prefix of each user and send it them. for example: dear prefix name family: -> dear Dr John Smith: you account is active.

Now i want to add the capability of editing this email context to admin part. The problem is some fields are dynamic. my code is like this:

 bodyMsg.Append( " Dear "+prefix+name+family+", thank you for accepting our request.Your username is your email and here is your Password :" + password);

As you see, name, family, prefix and password are dynamically change. Now admin needs to edit email context. He should do that from his control panel in a Rad Editor. For example change the place of name or family in email context. What i need is when admin used key words such as prefix, name or family the system detect the dynamic fields. and the email edited with dynamic fields place. can any body help me? thanks

Upvotes: 0

Views: 163

Answers (1)

Koen
Koen

Reputation: 2571

Last time I had to do something similar, I let them use predefined template-words in their text.

"Dear {prefix} {name} {family}, thank you for accepting....". 

Afterwards I replaced the template-words in the text with the values.

EDIT

We do this stuff with mailtemplates that needs to be sent by an app. The templates are created by someone and stored in the database. They've got documentation with a list of dynamic fields they can use in the mailtemplate, like in the example below: {ReplaceWithName}. In my app I'll replace those dynamic fields with the appropriate data:

Person person = GetPersonInfo(); //Gets the information of the person
string body = GetBodyFromDatabase(); //Retreives the created mailtemplate
body = body.Replace("{ReplaceWithName}", (person.Firstname + " " + person.Lastname)); //Do this for each dynamic field
mailMessage.Body = body;

This will of course put some responsibility to the user that creates those templates.

Upvotes: 2

Related Questions