I need to send emails to multiple contacts with a bar code based on Customer ID in a pdf attachment.
The requirement was to add the bar code in the attachment but due to salesforce limitation of accessing external images when rendered as pdf , made me modify the code to put the bar code in html email body.
I am using a third party freeware to generate the bar code , but still not able to generate barcode in the attachment.
Here is my vfpage mail template
<messaging:emailTemplate subject="Account Info" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >
Hi
Welcome to Stackexchange <br/>
Congratulations!
This is your Sample Email Template. <br/>
We are happy to provide you with the gift card <br/>
Kindly open the attachment for more details<br/>
<img id="theImage" src="http://www.barcodesinc.com/generator/image.php?code={!relatedTo.Cust_ID__c}&style=325&type=C128B&width=200&height=50&xres=1&font=3" />
</messaging:htmlEmailBody>
<messaging:attachment renderAs="PDF">
<html>
<head/>
<body>
<td> Hi {!relatedTo.name} </td><br/>
{!relatedTo.Phone} <br/>
{!relatedTo.Email_Address__c} <br/>
{!relatedTo.Cust_ID__c} <br/>
We are happy to provide you with the gift card
</body>
</html>
</messaging:attachment>
</messaging:emailTemplate>
Note: I have added barcodesinc.com in Remoe Site Settings.
My query is how can we make the image available in the attachment
Currently its coming as a broken image.
Best Answer
The remote site setting has nothing to do with the barcode appearing/not appearing.
Try the following:
I just tested this in my dev org with a standard field, and it works.
I suspect that your URL is getting confused because of unescaped characters, so this should fix it. You could also use URLENCODE.
I threw together some code that works in a PDF attachment, if you're really stuck. I've included the code as a Gist, but I'll also reproduce it here.
I used it in an email as follows: