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
NinetaMNinetaM 

Pdf attachment to Visualforce Email template not displaying images.

I have a Visualforce email template that has been working fine for a while now. The template has a
text body section and a pdf generated attachment with some images in it. The images are hosted under Documents in Salesforce and are available externally.
When the template is previewed the images show up just fine in the pdf attachment.

However, when the email goes out in response to people completing a web-to-lead form the pdf attachment has no images.

Has anything changed with the pdf rendering recently? How should the images be hosted for the pdf renderer to find them and correctly insert them into the doc.

I have also tested by inserting the images into the body of the email (by creating an html section) and the images showed up. However, in the pdf section they do not.

Please provide some assistance.

Thank you.

See code below:

-------------------------------------------------------------------------------------------------------------------
<messaging:emailTemplate recipientType="lead"
    relatedToType="lead"
    subject="Thank you for your donation"
    replyTo="..." >
    
    <messaging:plainTextEmailBody >        
    ...

    </messaging:plainTextEmailBody>
    
    <messaging:attachment renderas="pdf" filename="Shipping_Label.pdf">
    <html>
    <body>

<table border="0" cellpadding="30">
     <tr>
     <td align="center">
     <table border="0" cellpadding="10">
     <tr>
         <td colspan="3" align="left">
          Tracking ID: {!recipient.Id}
         </td>
     
         <td colspan="2" rowspan="5" align="left" valign="top">        
            <img src="https://na4.salesforce.com/servlet/servlet.ImageServer?id=01560000000REDF&oid=...&lastMod=1266688060000" width="121" height="216"/>                        
         </td>        
      </tr>
      
     <tr>
        <td align="left" valign="top" width="5">FROM:</td>
        
        <td align="left" width="250">
                 {!recipient.name}<br />
                 {!recipient.Street}<br />
                 {!recipient.City}, {!recipient.State} {!recipient.postalcode}<br /><br />
            POSTAGE DUE COMPUTED BY<br />
            DELIVERY UNIT<br /><br />
        </td>
        <td colspan="3">&nbsp;</td>
      </tr>

      <tr>
        <td align="right" valign="bottom" colspan="2"  width="250">
            POSTAGE_______<br /><br />
            TOTAL POSTAGE AND FEES DUE $_______<br /><br />
        </td>
        
        <td align="left" valign="bottom" colspan="2">
            <h1>PARCEL POST</h1>
        </td>
        <td></td>
      </tr>

        <tr>
            <td align="center" colspan="3">
        <img src="https://na4.salesforce.com/servlet/servlet.ImageServer?id=01560000000REDP&oid=....&lastMod=1266688150000" alt="Postage Due Unit" width="392" height="147" />   
            </td>
            <td></td>
            <td></td>
        </tr>
      </table>  
      </td>
      </tr>
      </table>
        </body>
    </html>
    </messaging:attachment>
</messaging:emailTemplate>
------------------------------------------------------------------------------------------------------------------------------------

Sean McMickle 11Sean McMickle 11

I know this is 10 years too late, however, I just ran into this issue myself.  Didn't change anything with the visualforce email at all, yet images vanished.  

I noticed that we had another email where the images were working, and the visualforce code looked exactly the same.  So I dug into the apex.

The only difference is that I found out that in a previous update, we had added a DML statement that fired before the email that had invisible images was sent out.   I simply the DML statements after the sending of the email, and TADA!  The images in the PDF magically reappeared. 

What a strange bug.

Sean McMickle 11Sean McMickle 11
I simply moved * the DML statements after sending the email instead of before.