5

I coded an e-mail template in Visualforce, however, some recipients see lines of code in the the e-mail that's sent to them. Please see example below:


Hello ,

Products to be include in the quotation are the following:

Product Code: if(!window.sfdcPage){window.sfdcPage = new ApexDetailPage();} UserContext.initialize({"networkId":"","locale":"en_US","labelLastModified":"1384456088000","isDefaultNetwork":true,"today":"11/27/2013 8:17 PM","timeFormat":"h:mm a","userPreferences":[{"index":112,"name":"HideInlineEditSplash","value":true},{"index":114,"name":"OverrideTaskSendNotification","value":true},{"index":115,"name":"DefaultTaskSendNotification","value":true},{"index":119,"name":"HideUserLayoutStdFieldInfo","value":false},{"index":116,"name":"HideRPPWarning","value":true},{"index":87,"name":"HideInlineSchedulingSplash","value":true},{"index":88,"name":"HideCRUCNotification","value":false},{"index":89,"name":"HideNewPLESplash","value":false},{"index":90,"name":"HideNewPLEWarnIE6","value":false},{"index":122,"name":"HideOverrideSharingMessage","value":false},{"index":91,"name":"HideProfileILEWarn","value":false},{"index":93,"name":"HideProfileElvVideo","value":false},{"index":97,"name":"ShowPicklistEditSplash","value":true},{"index":92,"name":"HideDataCategorySplash","value":false},{"index":128,"name":"ShowDealView","value":false},{"index":129,"name":"HideDealViewGuidedTour","value":false},{"index":132,"name":"HideKnowledgeFirstTimeSetupMsg","value":false},{"index":104,"name":"DefaultOffEntityPermsMsg","value":false},{"index":135,"name":"HideNewCsnSplash","value":true},{"index":101,"name":"HideBrowserWarning","value":false},{"index":139,"name":"HideDashboardBuilderGuidedTour","value":true},{"index":140,"name":"HideSchedulingGuidedTour","value":false},{"index":180,"name":"HideReportBuilderGuidedTour","value":true},{"index":183,"name":"HideAssociationQueueCallout","value":true},{"index":194,"name":"HideQTEBanner","value":false},{"index":193,"name":"HideChatterOnboardingSplash","value":true},{"index":195,"name":"HideSecondChatterOnboardingSplash","value":true},{"index":270,"name":"HideIDEGuidedTour","value":true},{"index":282,"name":"HideQueryToolGuidedTour","value":false},{"index":196,"name":"HideCSIGuidedTour","value":false},{"index":271,"name":"HideFewmetGuidedTour","value":false},{"index":272,"name":"HideEditorGuidedTour","value":false},{"index":205,"name":"HideApexTestGuidedTour","value":false},{"index":206,"name":"HideSetupProfileHeaderTour","value":true},{"index":207,"name":"HideSetupProfileObjectsAndTabsTour","value":false},{"index":213,"name":"DefaultOffArticleTypeEntityPermMsg","value":false},{"index":214,"name":"HideSelfInfluenceGetStarted","value":true},{"index":215,"name":"HideOtherInfluenceGetStarted","value":true},{"index":216,"name":"HideFeedToggleGuidedTour","value":false},{"index":268,"name":"ShowChatterTab178GuidedTour","value":false},{"index":275,"name":"HidePeopleTabDeprecationMsg","value":false},{"index":276,"name":"HideGroupTabDeprecationMsg","value":false},{"index":222,"name":"TouchExternalLinkReminderSuppression","value":false},{"index":224,"name":"HideUnifiedSearchGuidedTour","value":true},{"index":226,"name":"ShowDevContextMenu","value":true},{"index":227,"name":"HideWhatRecommenderForActivityQueues","value":false},{"index":228,"name":"HideLiveAgentFirstTimeSetupMsg","value":false},{"index":232,"name":"HideGroupAllowsGuestsMsgOnMemberWidget","value":false},{"index":233,"name":"HideGroupAllowsGuestsMsg","value":true},{"index":234,"name":"HideWhatAreGuestsMsg","value":false},{"index":235,"name":"HideNowAllowGuestsMsg","value":true},{"index":236,"name":"HideSocialAccountsAndContactsGuidedTour","value":true},{"index":237,"name":"HideAnalyticsHomeGuidedTour","value":true},{"index":238,"name":"ShowQuickCreateGuidedTour","value":false},{"index":245,"name":"HideFilePageGuidedTour","value":false},{"index":250,"name":"HideForecastingGuidedTour","value":false},{"index":242,"name":"TouchHideOptoutHover","value":false},{"index":251,"name":"HideBucketFieldGuide","value":false},{"index":263,"name":"HideSmartSearchCallOut","value":true},{"index":265,"name":"HideSocialProfilesKloutSplashScreen","value":false},{"index":273,"name":"ShowForecastingQuotaAttainment","value":false},{"index":280,"name":"HideForecastingQuotaColumn","value":false},{"index":301,"name":"HideManyWhoGuidedTour","value":true},{"index":284,"name":"HideExternalSharingModelGuidedTour","value":false},{"index":298,"name":"HideFileSyncBannerMsg","value":false},{"index":299,"name":"HideTestConsoleGuidedTour","value":true},{"index":300,"name":"HideNetworkSetupOverlayGettingStarted","value":false},{"index":302,"name":"HideManyWhoInlineEditTip","value":false},{"index":303,"name":"HideSetupV2WelcomeMessage","value":false},{"index":312,"name":"ForecastingShowQuantity","value":false},{"index":313,"name":"HideDataImporterIntroMsg","value":false},{"index":314,"name":"HideEnvironmentHubLightbox","value":false},{"index":316,"name":"HideSetupV2GuidedTour","value":true},{"index":317,"name":"HideFileSyncMobileDownloadDialog","value":false},{"index":318,"name":"HideHelpBannerQuickActionList","value":false},{"index":321,"name":"HideCustomEntityQuickActionCallout","value":true},{"index":322,"name":"HideEnhancedProfileHelpBubble","value":true},{"index":328,"name":"ForecastingHideZeroRows","value":false},{"index":330,"name":"HideEmbeddedComponentsFeatureCallout","value":false},{"index":340,"name":"HideS1BrowserUI","value":false}],"orgPreferences":[{"index":257,"name":"TabOrganizer","value":true}],"startOfWeek":"1","isAccessibleMode":false,"ampm":["AM","PM"],"renderMode":"RETRO","userId":"00540000000oOOR","dateTimeFormat":"M/d/yyyy h:mm a","dateFormat":"M/d/yyyy","uiSkin":"Theme3","language":"en_US","siteUrlPrefix":""});


It seems that their mail server or mail client adds the above extra code or does not understand it. Is there anything I can do on the Salesforce side to prevent this?

Any help would be greatly appreciated!

Thank you!

Edit: E-mail Template Code

<messaging:emailTemplate subject="Haivision Maintenance Contract has expired - {!relatedto.End_User__r.Name}" recipientType="Contact" relatedToType="Entitlement">
<messaging:htmlEmailBody >

<p></p>

Dear {!relatedto.Enduser_Support_Contact__r.Name},<br></br><br></br>

Our records indicate that {!relatedto.End_User__r.Name}'s Haivision Advance Maintenance Contract has expired.<br></br><br></br>   

Effective immediately, we must disable your access to the Haivision Download Center, the Support Portal, and the Haivision Customer Engineering team.<br></br><br></br> 

It is important to renew your Haivision Advance Maintenance Contract ASAP in order to continue to receive important software updates, firmware upgrades and access to Haivision Technical Support.<br></br><br></br> 

Please contact us at 514-334-5445 ext:1 or [email protected] to renew your Haivision Maintenance Contract.<br></br><br></br>

Below is the information related to the expired contract:<br></br><br></br>
- - - -  <br></br><br></br>


<apex:repeat value="{!relatedto.Assets__r}" var="o">

<apex:OutputPanel rendered="{!o.Retired__c == false}" >
<apex:OutputPanel rendered="{!o.Returned__c == false}">
<apex:OutputPanel rendered="{!o.Asset_Status__c == 'Expired'}">


               <b>Product Code:</b>&nbsp;

                          <apex:outputField value="{!o.Name}"/><br></br>

               <b>Description:</b>&nbsp;

                          <apex:outputField value="{!o.Product2.Name}"/><br></br>

               <b>Serial Number:</b>&nbsp;  

                        <apex:OutputPanel rendered="{!o.RMAed__c == false}">

                 <apex:outputField value="{!o.SerialNumber}"/><br></br>

</apex:OutputPanel>

<apex:OutputPanel rendered="{!o.RMAed__c == true}">

                 <apex:outputField value="{!o.New_Asset_Serial_Number__c}"/><br></br>

</apex:OutputPanel>

<b>Coverage Type:</b>&nbsp;

                   <apex:outputField value="{!o.Entitlement_Level__c}"/><br></br>

<b>Coverage End Date:</b>&nbsp;

                   <apex:outputField value="{!o.Entitlement_End_Date__c}" /><br></br>

<br></br>

</apex:OutputPanel>
</apex:OutputPanel>
</apex:OutputPanel>
</apex:repeat>


<p>Thank you. </p>
<p>Haivision</p>
<p>
<a href="https://na2.salesforce.com/{!relatedTo.ID}">*</a>
</p>
<p></p>
P.S. If you have already renewed your support, thank you.  <br /><br />

</messaging:htmlEmailBody>
</messaging:emailTemplate>
6
  • What mail client are the users viewing the message in? Are you able to get the complete email source including headers? (E.g. in gmail use the Show original) Commented Nov 28, 2013 at 18:46
  • That is definitely not coming from the recipients mail server or client. That's javascript included by Salesforce if certain components are used on a VF page. I've seen this code being created on a VF page which I red through AJAX as soon as I added an apex:outputField. Can you share your email template code?
    – FrankZ
    Commented Nov 28, 2013 at 18:59
  • Thanks for the reply! @Daniel Ballinger: I would not be able to get that information unfortunately. I would not be able to get the complete e-mail source.
    – andy
    Commented Nov 28, 2013 at 19:01
  • Thanks for the reply! @FrankZ It only happens to certain clients. Other clients I have view the correct content. I will add the e-mail template code to the top.
    – andy
    Commented Nov 28, 2013 at 19:04
  • 2
    @andy Try switching the <apex:outputField> to a <apex:outputText>. That should be fine for an email template and avoid the extra javascript that gets added for an outputfield. Commented Nov 28, 2013 at 19:55

3 Answers 3

3

I've experienced a similar issue. apex:outputText works fine until you try to output a rich text field. We allow our users to "insert a custom rich text paragraph" in many of our VF e-mail templates. The extra javascript also shows up in the comment field on the task object if you save the email as an activity. I know this doesn't answer the question but it appears I don't have the reputation to simply comment on the original post.

1

As you use apex:outputField to generate the content, Salesforce adds the JavaScript code right where you use that tag the first time. I assume some customers' email filters just remove the HTML script tags but leave the actual script within the email.

Why don't you just output your fields with <apex:outputText> instead of with <apex:outputField>?

Edit inspired by @Daniel Ballinger

0

I have also been struggling with this for the last several weeks. I couldn't find anyone that had fixed it previously so I went ahead and did it myself.

I had to write a custom component to do more work than outputText, but less overhead than outputField. Essentially it is a find and replace to make newlines into <br /> tags and I had to pre-escape the text string and tell outputText not to escape it for me, to keep the <br /> tags I added.

/component/

<apex:component controller="OutputTextHTML" access="global">
  <apex:attribute name="value" description="Text to be HTML formatted" type="String" assignTo="{!myText}"/>
  <apex:outputText value="{!myHTMLSafeText}" escape="false"/>
</apex:component>

/controller/

public class OutputTextHTML {
  public String myText{get;set;}
  public String myHTMLSafeText{
    get{
      if(myText == null)
        return myText;

      String myCleanText = myText.escapeHtml4();
      myCleanText = myCleanText.replaceAll('(\r\n)|(\n\r)|\r|\n','<br />');
      return myCleanText;
    }
  }
}

/test/

@isTest
public class OutputTextHTMLTest{
  public static testMethod void stringOutput(){
     OutputTextHTML htmlEncoder = new OutputTextHTML();
     //Catch null clause
     String out = htmlEncoder.myHTMLSafeText;
     htmlEncoder.myText = 'this is <a> test';
     out = htmlEncoder.myHTMLSafeText;
     System.assertEquals(out,'this is &lt;a&gt; test');

     htmlEncoder.myText = 'this\nis\na\ntest';
     out = htmlEncoder.myHTMLSafeText;
     System.assertEquals(out,'this<br />is<br />a<br />test');
  }
}

https://gist.github.com/aheber/040a5e0c2f84b68b6fdf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .