Help

The Community will be undergoing maintenance from Friday February 21 - Friday, February 28 and will be "read only" during this time. To learn more, check out our Announcements blog post.

Re: Use thumbnails from attachment fields in e-mail generated in automation

177 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Miles
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all,

I want to expand a script that assembles an e-mail using a few field values and sends a nice and simple daily report to stakeholder.

I want to add images inline from an attachment-type field. I use something like this:

 

 

 

 

if (clippings && clippings.length > 0) {
        for (let clip of clippings) {
            let imageUrl = clip.url;
            imageUrl = clip.thumbnails.large.url;

 

 

 

 

and later:

 

 

 

 

            if (imageUrl) {
                entryText += `<br><img src='${imageUrl}' alt='Clipping' style='max-width: 100%; height: auto;' /><br>`;
                console.log(`thumbnail added: ${encodedUrl}`);
            }

 

 

 

 

I then pass my output over to the next step:

 

 

 

 

outputText += `${entryText}<br><br>`;
output.set("emailOutput", outputText);

 

 

 

 

Although all URLS are definitely good (I paste them into the browser and the thumbnail shows), in the generated e-mail, only a few of them are displayed correctly as images. For most of them, a fragment of the URL shows up in the e-mail body. Even more strange, when I tested different code (i.e. markdown vs. HTML), suddenly other images are shown, while those that had worked before were now gone.

Could it be it is just not possible without moving the images to a public-facing service?

 

 

2 Replies 2

Ah yeah I encountered something similar where some of the image URLs had a format that's being confused with markdown, e.g. 'www.test.com/new_article_url', where the underscores would be used for italics or something

Try putting just the links themselves into a preview to see whether that's the case and then identify the patterns from there, and then try generating a preview of the email with the links manually created with either markdown or HTML to confirm stuff?

 

Miles
5 - Automation Enthusiast
5 - Automation Enthusiast

Thanks Adam, this was the critical advice I needed. We need to escape markdown, so I used this instead:

let safeUrl = encodedUrl.replace(/_/g, '\\_');
entryText += `<br><img src='${safeUrl}' alt='Clipping' style='max-width: 100%; height: auto;' /><br>`;

Thanks again!