I am using traditional web application for sending emails. This application is being consumed by some other module that is passing email_body as a parameter.
If we use expression for displaying email_body, it is rendered as it is in email.
However, email body has data specific to each user to which mail would be sent, which needs to be replaced while creating mail.
Below is what is passed as email_body from main module:
<h1>Hello {UserName}</h1>
<p>Welcome to Outsystems. We need to confirm your email address {Email_address}</p>
How to replace that user specific data in expression
Hi Rakhi,
As a solution for the mentioned use-case, you can introduce two input parameter to the Email Template, let's say Username and UserEmail then refer the input parameter value within the expression as shown below...
"<h1>Hello "+ EncodeHtml(Username) + "</h1> <p>Welcome to Outsystems. We need to confirm your email address " + EncodeHtml(UserEmail) +"</p>"
Hope this helps you!
Regards,
Benjith Sam
Hello Rakhi,
You have a few options. If your text is static then Benjith's suggestion will work just fine. If your text is dynamic, e.g. stored in a database, then you can either use Regex_Replace in the Text module, or you can import a .NET template engine.
If you use Regex_Replace, it will be a very basic replace and you will have to ensure you properly escape regex characters. I've included a simple example on what you could use. In this case, you can call it like this:
For anything more complex, I would suggest a .NET template engine.
EDIT: I didn't do it in my sample, but if you know the output is HTML then you should use EncodeHtml in the Regex_Replace, similar to Benjith
Craig St.Jean wrote:
Thank you. Was trying to use both static text and one retrieving from database.
This solution worked!! Thanks
Since this is an exact search you can take the expression in a variable and can use Outsystems's in build Replace() function to replace the user-specific information.
Thanks,
Sachin
Sachin Mahawar wrote:
Thank you. It worked.