ในการส่งอีเมลด้วย Google Script นั้นหลายท่านอาจยังไม่ทราบว่าเราสามารถสร้าง Template Email ให้ดูดีมีระดับแบบฉบับองค์กรใช้กันได้เลยนะครับ ไปลุยกันเลยครับ 🙂 🙂 🙂
// Presented by BrilliantPy /*######################### Editable1 Start #########################*/ let sheetName = "การตอบแบบฟอร์ม 1"; let indexCol = {"ประทับเวลา":0,"ชื่อ - สกุล":1,"อีเมล":2,"send_status":3} let emailCol = indexCol["อีเมล"]; let statusCol = indexCol["send_status"]; let emailSubject = "แบบฟอร์มใบลาสำหรับพนักงาน"; let logoUrl = "https://brilliantpy.com/wp-content/uploads/2021/07/cropped-logo_circle_v2_whitebg.jpg"; let addressFooterEmail = "72 Phahon Yothin Road, Sam Sen Nai, Phaya Thai, BKK 10400 THA"; /*######################### Editable1 End #########################*/ // Init let sentStatus = "SENT"; let ss,sheet,lastRow,lastCol,range,values,title; let curData; async function templateEmail() { /*######################### Editable2 Start #########################*/ function getBodyEmail() { let result = `คุณ ${curData[indexCol['ชื่อ - สกุล']]} แผนก Dev ได้ยื่นคำร้องขอ ลากิจ ตั้งแต่ 13/09/2022 จนถึง 14/09/2022\nจึงเรียนแจ้งเพื่อขออนุมัติการลา กรุณากดที่ลิงก์เพื่ออนุมัติการลา`; return result; } /*######################### Editable2 End #########################*/ await initSpreadSheet(); for (let i=0;i<lastRow;i++) { if (i == 0) { continue; } curData = values[i]; let curStatus = curData[statusCol]; let curEmail = curData[emailCol]; let numRow = i+1; if (curStatus == sentStatus) { continue; } // console.log(renderHtmlBody()) await sendEmail(curEmail,numRow); } function renderHtmlBody() { let result = ""; result = `<div style="max-width: 600px;text-align: center;margin: auto;color: rgb(34,34,34);"> <img style="width: 80px;height: 80px;max-width: 80px;max-height: 80px;border-radius: 10px;background-color: white;margin: auto;" class="logo" src="${logoUrl}"> <div style="font-size: 26px;padding-top: 30px;color: rgb(34,34,34);">${emailSubject}</div> <p style="font-size: 16px;color: rgb(34,34,34);">${getBodyEmail()}</p> <div style="text-align: center;color: black"> <a href="#" style="background-color: #4CAF50; width: 150px; color: white; padding: 16px 32px; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 25px; cursor: pointer; border-radius: 0.25rem;">อนุมัติ</a> <a href="#" style="background-color: #f44336; width: 150px; color: white; padding: 16px 32px; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 25px; cursor: pointer; border-radius: 0.25rem;">ไม่อนุมัติ</a> </div> <div style="padding-top: 30px;color:rgb(34,34,34);">© 2022 All Right Reserved • Terms and Privacy<br>${addressFooterEmail}</div> </div>`; return result; } function sendEmail(email,numRow) { return new Promise(function(resolve,reject) { try { MailApp.sendEmail({ to: email, subject: emailSubject, htmlBody: renderHtmlBody(), }); sheet.getRange(numRow,toNumCol(statusCol)).setValue(sentStatus); resolve(); console.log('sendEmail completed') } catch(e) { reject(`[Error]:sendEmail error with email (${email}),${e}`); } }); } } async function initSpreadSheet() { return new Promise(function(resolve) { ss = SpreadsheetApp.getActive(); sheet = ss.getSheetByName(sheetName); lastRow = sheet.getLastRow(); lastCol = sheet.getLastColumn(); range = sheet.getDataRange(); values = range.getValues(); title = values[0]; resolve(); console.log('initSpreadSheet completed'); }); } function toNumCol(indexCol) { return indexCol+1; }
Thanks for sharing superb informations. Your web site is so cool. I’m impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched all over the place and just could not come across. What a perfect site.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
Thanks for another fantastic article. Where else could anybody get that type of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
I am typically to running a blog and i really respect your content. The article has actually peaks my interest. I’m going to bookmark your site and maintain checking for new information.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
There is visibly a bundle to realize about this. I suppose you made some nice points in features also.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
It?¦s actually a great and helpful piece of information. I am happy that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
fantastic put up, very informative. I’m wondering why the other specialists of this sector do not notice this. You should proceed your writing. I am confident, you’ve a huge readers’ base already!
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
Would love to incessantly get updated great site! .
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy
Thanks for another excellent post. Where else may anyone get that type of information in such a perfect method of writing? I’ve a presentation subsequent week, and I am at the look for such info.
Thank you. You can follow us either way.
youtube : https://www.youtube.com/@brilliantpy/videos
Facebook: https://web.facebook.com/BrilliantPy