Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > EmailTemplate - Using html View modes: 
User avatar
Member
Member
j.wijst-hotmail - 11/2/2010 5:26:32 AM
   
EmailTemplate - Using html
I've got an HTML email template and in the code behind I put all my custom values into the template. Now everything works well until I want to put a html code into a variable. When I do this and look at the email the EmailSender wants to send they encoded the html.

Now I don't want this to happen so I can put a table into one of my variables on my emailtemplate.

How can I achieve this?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/2/2010 6:03:44 AM
   
RE:EmailTemplate - Using html
Hi,

Could you please try to call CMS.GLobalHelper.HTMLHelper.HTMLEncode(string inputText) method to encode your html tags before sending the email using the EmailSender?

If the above method does not help you, could you please describe with more details how was your email template created, how is used and provide us its code?

Best regards,
Ivana Tomanickova

User avatar
Member
Member
j.wijst-hotmail - 11/2/2010 7:06:25 AM
   
RE:EmailTemplate - Using html
Hi Ivana,

Thanks for your response.

The encoder didn't help.

So what I do in steps:
1) I've got an html email template in kentico, this template has a few custom variables in it declareded like: {% ProcessCustomMacro("productlijst", "") %} etc.

2) This is what I do at an page after the shoppingprocess:

OrderInfo orderinfo = OrderInfoProvider.GetOrderInfo(Convert.ToInt32(OgoneResponse.OrderId));
EmailTemplateInfo template = EmailTemplateProvider.GetEmailTemplate("T4U.ETicketBetaling", CMSContext.CurrentSite.SiteName);
EmailMessage message = new EmailMessage();
message.Subject = "Ticket4U - Betalingsbevestiging E-Ticket - " + OgoneResponse.OrderId.ToString();
message.Recipients = CustomerInfoProvider.GetCustomerInfo(orderinfo.OrderCustomerID).CustomerEmail;
//message.Body = template.TemplateText;
CMS.GlobalHelper.MacroResolver resolver = new CMS.GlobalHelper.MacroResolver();
resolver.ResolveMacros(message.Body);

EmailSender.SendEmailWithTemplateText(CMSContext.CurrentSiteName, message, template, resolver, true);


Now I've made a customresolver in app_code/global/cms/cmscustom.cs.
The method in this resolver contains that it replaces the {% ProcessCustomMacro("productlijst", "") %} with:
<table border='1px' cellpadding='5' cellspacing='0' style='border: solid 1px Silver; font-size: x-small;'><tr align='left' valign='top'><td align='left' valign='top'>Product Naam</td><td align='left' valign='top'>Aantal</td><td align='left' valign='top'>Prijs Per Product (exl. btw)</td></tr></table> 


Now the problem is that when he sends the mail he decodes the html I send and makes it:
<table border='1px' cellpadding='5' cellspacing='0' style='border: solid 1px Silver; font-size: x-small;'><tr align='left' valign='top'><td align='left' valign='top'>Product Naam</td><td align='left' valign='top'>Aantal</td><td align='left' valign='top'>Prijs Per Product (exl. btw)</td></tr></table> 


As you this is not what I want to send to my customers because the email wont show this in html.

Hope you can help me with the problem, thanks in advance.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/2/2010 8:02:55 AM
   
RE:EmailTemplate - Using html
Hi,

Could you please try to insert following line into definition of your custom macro?

sender.AllowParameters = false;

If your custom macro returns for example "<td>something</td>", tags should be part of the html code in your email template.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
j.wijst-hotmail - 11/2/2010 8:08:08 AM
   
RE:EmailTemplate - Using html
kentico_ivanat wrote: Hi,

Could you please try to insert following line into definition of your custom macro?

sender.AllowParameters = false;

If your custom macro returns for example "<td>something</td>", tags should be part of the html code in your email template.

Best regards,
Ivana Tomanickova

The alowparamenters won't work.

Also isn't it kind of weird not being able to return <td> etc into the email template?
How am I supposed to return a table of all the products in a order then?

It's normal to send an list of bought products in the payment email.

Best regards,
Julian

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 11/3/2010 3:57:22 PM
   
RE:EmailTemplate - Using html
Hi,

What version of CMS are you using? I tested the behavior with a default 5.5 installation and macro was resolved correctly => table code was created correctly in a received email.

Could you please compare if your macro is similar to the following? I used " instead of ' in the html code definition.

case "productlist":

match = true;
sender.AllowParameters = false;

result="<table border=\"1px\" cellpadding=\"5\" cellspacing=\"0\" style=\"border: solid 1px Silver; font-size: x-small;\"><tr align=\"left\" valign=\"top\"><td align=\"left\" valign=\"top\">Product Naam</td><td align=\"left\" valign=\"top\">Aantal</td><td align=\"left\" valign=\"top\">Prijs Per Product (exl. btw)</td></tr></table>";
break;


And I inserted following code into Plain text version field of the email template (default Boards - Notification to board moderators):


Product list: {% ProcessCustomMacro("productlist", "") %}


Could you please try to test above macro with some default template? If it would be working for you as well, we could continue with debugging.

Best regards,
Ivana Tomanickova


User avatar
Member
Member
DHood-CPUonline - 9/8/2013 2:33:01 PM
   
RE:EmailTemplate - Using html
Should this also work in version 7?

User avatar
Member
Member
kentico_sandroj - 9/8/2013 2:41:21 PM
   
RE:EmailTemplate - Using html
Hello,

Would you mind clarifying which part you're having an issue with? Encoding or resolving the macro? This FAQ may answer your question as well.

Best Regards,
Sandro

User avatar
Member
Member
DHood-CPUonline - 9/8/2013 2:54:31 PM
   
RE:EmailTemplate - Using html
For the custom resolver, we already have VB code in the project. The poster mentions he created his in CS.

Now I've made a customresolver in app_code/global/cms/cmscustom.cs.