如何在我的代码中添加社交媒体图标?

时间:2017-06-08 19:12:14

标签: javascript html google-apps-script social-networking

这是我到目前为止的代码。 在电子邮件的最后,我想提供像我在网上免费找到的社交图标。并引导他们到我所拥有的相应链接。减去Skype。

https://codepen.io/anon/pen/QgjeXw

function sendEmails() {
  var allData,counter,emailAddress,fourRowsOfData,i,lastRow,
      message,messageStart,messageEnd,numRows,
      row,sheet,startRow,studentName,subject;

  //USER INPUT
  startRow = 2;  // First row of data to process
  numRows = 4;   // Number of rows to process
  subject = "Camp Pursuit: Report Card ";
  messageStart = "Dear Parents,"+'\n' +'\n' +
  "Every week at Camp Pursuit, we ask the teachers to make observations about how the kiddos did." +'\n' +
  "We know that one week isn't enough to truly know a child, so we call this our " +"Glows, Grows, & Apropos." +'\n' +
    "Meaning..." + '\n' +'\n' +
    "Glows: Positive things the teacher noticed" +'\n' +
    "Grows: Areas for continued growth" +'\n' +
    "Apropos: Ways to continue your son/daughter's enrichment" +'\n' +
    "We hope you appreciate seeing what the teachers saw last week, and perhaps you can use some of"+'\n' +
    "the recommendations for further enrichment this summer.  Feel free to let us know your thoughts on the camp through our anonymous online survey."+'\n' +
     "Your feedback helps us improve the experience for all kiddos! "+'\n' + 
"Survey Link: https://docs.google.com/forms/d/1g4LvA9a8sdKECr1yvp5uOoPnvKACFm3HvbTBfvQGRyo/viewform?usp=send_form" +'\n' +
"We look forward to seeing your child at our programs throughout the year!" +'\n' +
"Sincerely, "+'\n' +
"The Camp Pursuit Team"
+'\n';
  //END USER INPUT

  sheet = SpreadsheetApp.getActiveSheet();
  lastRow = sheet.getLastRow();

  allData = sheet.getRange(startRow, 1, lastRow-startRow, 10);// Get All data first

  counter = 0;

  while (counter < lastRow-startRow) {
    Logger.log('counter: ' + counter)

    fourRowsOfData = sheet.getRange(startRow + counter, 1, numRows, 6).getValues();
    emailAddress = fourRowsOfData[0][0];  // First column of first row
    Logger.log('emailAddress: ' + emailAddress)

    studentName = fourRowsOfData[0][1];

    messageEnd = "";//Reset on every outer loop

    for (i = 0; i < numRows; i++) {//loop numRows times - once for each row
        row = fourRowsOfData[i];

        messageEnd = messageEnd + '\n' +
            "Class: " + row[2] + '\n' +'\n' +
              "Glows: " + row[3]+ '\n' +
              "Grows: " + row[4] +'\n' +
                "Apropos: " + row[5] +'\n';  
    }

    message = messageStart + "\n" + studentName + "\n" + messageEnd;

    MailApp.sendEmail(emailAddress, subject, message);//Send the email outside of inner loop    
    counter+=numRows;//Increment counter by number of rows to process
  }
}

1 个答案:

答案 0 :(得分:0)

我认为您无法使用codepen中的示例,因为它们涉及大量代码(例如,用于显示悬停状态等)。但是,您可以将按钮保存为图像并将其存储在云端硬盘或其他位置。

下一步是从外部网址获取图片的blob

var imageBlob = UrlFetchApp.fetch(yourImageUrl).getBlob(); 

或来自云端硬盘

   var imageBlob = DriveApp.getFileById(yourFileId).getBlob();

为您的电子邮件的html正文构建字符串。使用'br'标记表示换行符。将图片包裹在“a”标签中,以便将图片链接到外部网站。在'img'标签的'src'属性中,为您的图片blob创建一个唯一的ID,并将其放在'cid'之后。

var body = "<h1> Header </h1> <br />" +
            "<a href='www.example.com'><img src='cid:uid' /></a> Image <br />" +  
            "Content";

而不是字符串参数,将以下对象传递给MailApp.sendEmail()方法。在运行时,脚本将解析存储在“body”变量中的字符串并创建html输出,使用cid标识符从inlineImages对象中检索图像。 “inlineImages”对象的属性名称必须与您在“body”

中为图像创建的ID匹配
MailApp.sendEmail({
    to: "recipient@example.com",
    subject: "subject",
    htmlBody: body,
    inlineImages: {

      uid: imageBlob

    }

});

连接字符串以生成html主体不是最好的解决方案。考虑使用HtmlService https://developers.google.com/apps-script/guides/html/

创建可重用的html模板