0

We are querying data from the Contact object from Sales Cloud to Marketing Cloud and sending email templates along with dynamic attachments to contact emails. Here we are sending the PDF URL stored in the attachment1 field of the data extension as an attachment using the below AMP script code, now HTML code is stored in the attachment2 field, how to send the HTML code in the attachment2 field as an attachment?

%%[ 
set @Attachment_URL=Attachment1
if (@Attachment_URL!='') then 
AttachFile("HTTP", @Attachment_URL, 'Document') 
 endif 
 ]%%
1
  • What do you mean by “send html as attachment”? Html itself cannot be attached
    – zuzannamj
    Commented Apr 17, 2023 at 15:48

2 Answers 2

1

In order to use the AttachFile function, the file needs to already be hosted from somewhere. So the URL in "attachment1" field can work with the function.


If you insist to use the HTML code for the PDF file then it would require extra effort since Marketing Cloud doesn't have a native feature to convert the HTML code to a PDF file. I can brief the idea as the following:

  • Find a (pure) Javascript library to convert HTML code to PDF and put it in a cloudpage in Code Resource type so you can reuse it in future.
  • Create a cloudpage as a handler page where you refer to the Javascript library above and the HTML structure for the PDF file.
  • Create a download button with the download function inside the handler page.
  • Pass parameters into the handler page through CloudPagesURL function in the email, so the PDF file can include/be personalized with customer information.
  • When recipient clicks into the CloudPagesURL, it should redirect that person to the handler page where they can download the PDF file from there.

The handler page will take the role that receive parameters, personalize information in the HTML code, convert the HTML code to PDF file and let recipient download it. The AttachFile function has nothing to do in this way.

1

I don't think loading entire email HTML from a DE field is the best way to send email in SFMC. Instead you should create a HTML email template in SFMC with the basic content and structures, and load personalisation variables from data extension fields and render email content.

AttachFile is a paid feature so you need to contact Salesforce account manager to buy them in bulk. You can attach the file from a public url or from SFMC enhanced SFTP, if the PDF content contains PII or PCI, storing PDFs in SFMC SFTP may be a preferred option. If these PDFs are specific for each subscriber, you can follow a naming convention for those PDFs, e.g. using contactKey in naming convention, so you can dynamically construct name parameter in AttachFile function using contactKey(subscriberKey) or other identifiers available in data extension

You must log in to answer this question.

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