Inline Images - how to add this capability to current script?

80 views
Skip to first unread message

Allan Berkovitz

unread,
Oct 17, 2018, 4:42:49 PM10/17/18
to FormEmailer
I've looked around at some of the questions on how to add an inline image into Gmail and there doesn't seem to really be an answer.
Using HTML, the image shows up as an attachment in Gmail, but the URL is still visible within the email send when the script is run after submitting a form.

I found this online https://ctrlq.org/code/19738-inline-images-gmail and was wondering if there was anyway to incorporate that into the current script?
I have two formulas happening in my spreadsheet from the form.

One is a list of employee names, that retrieves an email address based on the name chosen in a pull down menu for the customized email to send to.
The second is a list of categories with an image associted with each category. 

What I'm trying to do is have the image associated with the category embedded inline in the email. I've tried this with html directly in the configuration, however, I end up with the HTML URL in the message and not the actual image in the body of the message. How would I incorporate this: https://ctrlq.org/code/19738-inline-images-gmail into the current script to allow for inline images properly placed in an email send from formEmailer?

Thanks in advance,
Allan

Allan Berkovitz

unread,
Oct 18, 2018, 11:32:32 AM10/18/18
to FormEmailer
And there's this as well on creating inline images.

I'm just not experienced enough to know how to link a variable for the images (URLs of the images as values in a column of cells in Google Sheets) to a placeholder for the FormEmailer Settings. I'm not seeing which arguments in your script allow for this. Any suggestions would be appreciated.

Henrique Abreu

unread,
Oct 18, 2018, 1:10:51 PM10/18/18
to FormEmailer Group
Well, for this to work it'll have to change the code.

It is somewhat straightforward to get it to work for your specific scenario.
It is kind of tough to have it in a generic way, with a nice interface that would be flexible enough to suit more people.

Unfortunately, I don't have time to work on those. But if you want to get your hands on it, please feel free. I'll even publish your code to FormEmailer's web page if care to share something reusable.

Henrique G. Abreu


--
You received this message because you are subscribed to the Google Groups "FormEmailer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to formemailer...@googlegroups.com.
To post to this group, send email to forme...@googlegroups.com.
Visit this group at https://groups.google.com/group/formemailer.
For more options, visit https://groups.google.com/d/optout.

Allan Berkovitz

unread,
Oct 18, 2018, 2:00:15 PM10/18/18
to FormEmailer
Does using the pipe "|" after the placeholder name in the html allow me to format the value of the placeholder with code? That may be a way around it if that's possible.


On Thursday, October 18, 2018 at 1:10:51 PM UTC-4, Henrique Abreu wrote:
Well, for this to work it'll have to change the code.

It is somewhat straightforward to get it to work for your specific scenario.
It is kind of tough to have it in a generic way, with a nice interface that would be flexible enough to suit more people.

Unfortunately, I don't have time to work on those. But if you want to get your hands on it, please feel free. I'll even publish your code to FormEmailer's web page if care to share something reusable.

Henrique G. Abreu


Henrique Abreu

unread,
Oct 18, 2018, 2:05:58 PM10/18/18
to FormEmailer Group
No, it does not. But that wouldn't do it either. Because in the end you have to get the image blob in the attachment parameter, and that requires changing the code.

Henrique G. Abreu

Message has been deleted

Henrique Abreu

unread,
Oct 18, 2018, 2:35:11 PM10/18/18
to FormEmailer Group
Are you trying to build a generic thing or just solve for your use case?
I suggest you get your particular case working first and then move on to a generic solution.

So, to solve for you alone you shouldn't need to deal with placeholders at all.
Just put the html img tag in your email template, just like all the rest of the email there.
Then, in FormEmailer's code, fetch the imgBlob, like you've shown and attach it.

Henrique G. Abreu


On Thu, Oct 18, 2018 at 1:31 PM Allan Berkovitz via FormEmailer <formemailer+APn2wQelajnRzLiSXmvS...@googlegroups.com> wrote:
OK.

Is there a way to add code to add an additional format called IMG?

So, for example, we can pipe the format "IMG" as in #placeholder|IMG#, and that takes the placeholder and enters it in as the variable URL for the following (with instruction for users to ensure that the value must be in URL format for images):

function inlineImage() {
  var imgUrl = "[REFER TO PLACEHOLDER HERE]";  //<--- THIS IS WHERE THE PLACEHOLDER IS SUBSTITUTED
  var imgBlob = UrlFetchApp
                 .fetch(imgUrl)
                 .getBlob()
                 .setName("imgBlob");
}

MailApp.sendEmail({
    htmlBody: "<img src='cid:imagVar'>",    
    inlineImages:
      {
        imgVar: imgBlob,
      }
  });


...or am I completely way off. 

Allan Berkovitz

unread,
Oct 18, 2018, 2:35:45 PM10/18/18
to FormEmailer
Is there a way to add an additional format, IMG, as in #placeholder | IMG# 
Where would I do that?
I was thinking this would alleviate the need to change a lot of code, just add a format, with the instruction to users that this format requires that the values be in the proper URL expression for pulling into the below snippet.



function inlineImage() {
var imgUrl = "[REFER TO PLACEHOLDER HERE]";  //<--- THIS IS WHERE PLACEHOLDER IS SUBSTITUTED
var imgBlob = UrlFetchApp
                  .fetch(imgUrl)
                  .getBlob()
                  .setName("imgBlob");
}

MailApp.sendEmail({
    htmlBody: "<img src='cid:imagVar'>",    
    inlineImages:
      {
        imgVar: imgBlob,
      }
  });

On Thursday, October 18, 2018 at 2:05:58 PM UTC-4, Henrique Abreu wrote:
No, it does not. But that wouldn't do it either. Because in the end you have to get the image blob in the attachment parameter, and that requires changing the code.

Henrique G. Abreu


Allan Berkovitz

unread,
Oct 18, 2018, 2:41:10 PM10/18/18
to FormEmailer
Generic as well, but first and foremost for my use currently. 
I have a form that people use pulldown menu to choose a co-worker which references a list on another sheet, that gets the email address and sends a formatted email using your script to the co-worker.
Then another question on the form has 6 images as multiple choice. The image selected should be inline in the email to the co-worker. (this is form we use to nominate fellow co-workers for awards for going above the normal at the office, in six categories. The winner, chosen every six months, receives a small bonus to their paycheck.)
So I have a list of the categories in the google sheet that references another column with the URL to the images respectively.
The formula on the response sheet pulls the URL based on the category chosen, and that URL should be used to create an inline image in the email.
If it were just one image, this wouldn't be an issue, but it's one of six images per form/email. 

I can share the form with you if you like so you understand what I'm doing.
Reply all
Reply to author
Forward
0 new messages