2017-06-08 49 views
0

這是我到目前爲止的代碼。 在電子郵件的結尾處,我想提供這些社交圖標,例如我在網上免費找到的圖標。並將他們引導至我擁有的相應鏈接。減去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 
    } 
} 

回答

0

我不認爲你可以,因爲它們涉及大量的代碼使用來自codepen實例(例如,用於顯示懸停狀態,等等)。但是,您可以將這些按鈕保存爲圖像並將它們存儲在您的雲端硬盤或其他地方。

下一個步驟是從外部URL

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」變量中的字符串,並使用cid標識符從inlineImages對象中檢索圖像,從而創建html輸出。 「inlineImages」對象的屬性名必須你把你的圖像創建的id在「身體」

MailApp.sendEmail({ 
    to: "[email protected]", 
    subject: "subject", 
    htmlBody: body, 
    inlineImages: { 

     uid: imageBlob 

    } 

}); 

串聯字符串生成HTML的身體雖然不是最好的解決方案相匹配。考慮使用HtmlService創建可重用的html模板https://developers.google.com/apps-script/guides/html/

相關問題