function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael_MantouvalosMichael_Mantouvalos 

Visualforce Email template is not rendering and it shows Html Tags when email is being sent

Hello everyone,

I have created a visualforce Email template that uses a visualforce component to display some records in a form of a table. The problem is that inside my visualforce component whatever HTML I use, it does not render the HTML and in Email preview, it shows  the HTML tags. For example I want to create a simple table  isnide my component :

Email Template :
<messaging:emailTemplate subject="test subject" recipientType="Contact" relatedToType="Booking__c">
<messaging:plainTextEmailBody >

<c:PaxInformation/>

Congratulations!
This is your new Visualforce Email Template.

Dear Partner,  
blah blah blah.......

</messaging:plainTextEmailBody>
</messaging:emailTemplate>

Visualforce Component (Name : PaxInformation)

<apex:component controller = "PaxInformationController" access="global" >

<table class="table">
    <thead>    
        <tr>
            <th>Opportunity Name</th> 
            <th>Opportunity Description</th>
            <th>Opportunity Amount</th>
        </tr>
    </thead>        
</table>
</apex:component>


Final Email received (body): 


User-added image


____________________________________

Any ideas on why is this happening?
Why it does not render the html tags to an actual html table?


Thanks in advance,
Michael.
Best Answer chosen by Michael_Mantouvalos
SwethaSwetha (Salesforce Developers) 
HI Michael,
I was able to figure this out. You need to use 
<messaging:htmlEmailBody> instead of <messaging:plainTextEmailBody> tag.

Try this code:
 
<messaging:emailTemplate subject="test subject" recipientType="Contact" relatedToType="Booking__c" >
<messaging:htmlEmailBody>

<c:PaxInformation />

Congratulations!
This is your new Visualforce Email Template.

Dear Partner,  
blah blah blah.......

</messaging:htmlEmailBody>
</messaging:emailTemplate>

If this information helps, please mark the answer as best.Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Michael,
Does this happen only in Outlook or across other email clients like Gmail/yahoo etc too? Thanks
Michael_MantouvalosMichael_Mantouvalos
Hi Swetha, thanks for the reply.

It doesn't have to do with outlook or Gmail etc.. it has to do with salesforce. because in the preview of my email template I also get the unrenderd html table. For my test I used Gmail client 
 
SwethaSwetha (Salesforce Developers) 
Thanks. I will do a repro in my org and get back as I have more inputs.Thank you
Michael_MantouvalosMichael_Mantouvalos
Thank you very much! 
Ashvin JAshvin J
Hi Micheal, 

Make sure to use below formatting in your component. 
 
<messaging:emailTemplate subject="test subject" recipientType="Contact" relatedToType="Booking__c">
<messaging:plainTextEmailBody >

<html>
<body>
<c:PaxInformation/>
</body>
<html>

Congratulations!
This is your new Visualforce Email Template.

Dear Partner,  
blah blah blah.......

</messaging:plainTextEmailBody>
</messaging:emailTemplate>
Thanks.
Ashvin

 
Michael_MantouvalosMichael_Mantouvalos

Hi Ashvin ,

Thanks for the reply!

Unfortunately this did not made any difference.
The email I get now is :

User-added image

SwethaSwetha (Salesforce Developers) 
HI Michael,
I was able to figure this out. You need to use 
<messaging:htmlEmailBody> instead of <messaging:plainTextEmailBody> tag.

Try this code:
 
<messaging:emailTemplate subject="test subject" recipientType="Contact" relatedToType="Booking__c" >
<messaging:htmlEmailBody>

<c:PaxInformation />

Congratulations!
This is your new Visualforce Email Template.

Dear Partner,  
blah blah blah.......

</messaging:htmlEmailBody>
</messaging:emailTemplate>

If this information helps, please mark the answer as best.Thank you
This was selected as the best answer
Michael_MantouvalosMichael_Mantouvalos
Thank you Swetha! that worked great