簡體   English   中英

如何在Gmail中創建電子郵件模板,以將下一周的摘要發送到多個電子郵件地址

[英]How to create an email template in Gmail that sends a summary of the upcoming week to multiple email addresses

我為我的同事設置了一個用於行業活動的Google日歷,我想每周發送一次電子郵件(通過Gmail),以總結此Google日歷中下周的活動。 我很樂意創建視覺模板並將其設置為每周自動發送,但是我需要一些幫助以獲取Google日歷信息。

我為此調查了插件,但無法在工作電子郵件中使用它們。

我找到了用於在網站上顯示Google日歷事件信息的代碼,但是之前我沒有使用公共apiKey或網絡應用程序客戶端ID。 我出於安全原因對使用它們感到謹慎,因為這是給我的工作電子郵件的密碼-我對安全設置此設置沒有信心。

 <html> <head> </head> <body bgcolor="black" text="white" link="#00ffff" vlink="green" alink="yellow"> <script> var clientId = 'YOUR_CLIENT_ID HERE'; //choose web app client Id, redirect URI and Javascript origin set to http://localhost var apiKey = 'YOUR_APIKEY_HERE'; //choose public apiKey, any IP allowed (leave blank the allowed IP boxes in Google Dev Console) var userEmail = "YOUR_ADDRESS@gmail.com"; //your calendar Id var userTimeZone = "YOUR_TIME_ZONE_HERE"; //example "Rome" "Los_Angeles" ecc... var maxRows = 10; //events to shown var calName = "YOUR CALENDAR NAME"; //name of calendar (write what you want, doesn't matter) var scopes = 'https://www.googleapis.com/auth/calendar'; //--------------------- Add a 0 to numbers function padNum(num) { if (num <= 9) { return "0" + num; } return num; } //--------------------- end //--------------------- From 24h to Am/Pm function AmPm(num) { if (num <= 12) { return "am " + num; } return "pm " + padNum(num - 12); } //--------------------- end //--------------------- num Month to String function monthString(num) { if (num === "01") { return "JAN"; } else if (num === "02") { return "FEB"; } else if (num === "03") { return "MAR"; } else if (num === "04") { return "APR"; } else if (num === "05") { return "MAJ"; } else if (num === "06") { return "JUN"; } else if (num === "07") { return "JUL"; } else if (num === "08") { return "AUG"; } else if (num === "09") { return "SEP"; } else if (num === "10") { return "OCT"; } else if (num === "11") { return "NOV"; } else if (num === "12") { return "DEC"; } } //--------------------- end //--------------------- from num to day of week function dayString(num){ if (num == "1") { return "mon" } else if (num == "2") { return "tue" } else if (num == "3") { return "wed" } else if (num == "4") { return "thu" } else if (num == "5") { return "fri" } else if (num == "6") { return "sat" } else if (num == "0") { return "sun" } } //--------------------- end //--------------------- client CALL function handleClientLoad() { gapi.client.setApiKey(apiKey); checkAuth(); } //--------------------- end //--------------------- check Auth function checkAuth() { gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult); } //--------------------- end //--------------------- handle result and make CALL function handleAuthResult(authResult) { if (authResult) { makeApiCall(); } } //--------------------- end //--------------------- API CALL itself function makeApiCall() { var today = new Date(); //today date gapi.client.load('calendar', 'v3', function () { var request = gapi.client.calendar.events.list({ 'calendarId' : userEmail, 'timeZone' : userTimeZone, 'singleEvents': true, 'timeMin': today.toISOString(), //gathers only events not happened yet 'maxResults': maxRows, 'orderBy': 'startTime'}); request.execute(function (resp) { for (var i = 0; i < resp.items.length; i++) { var li = document.createElement('li'); var item = resp.items[i]; var classes = []; var allDay = item.start.date? true : false; var startDT = allDay ? item.start.date : item.start.dateTime; var dateTime = startDT.split("T"); //split date from time var date = dateTime[0].split("-"); //split yyyy mm dd var startYear = date[0]; var startMonth = monthString(date[1]); var startDay = date[2]; var startDateISO = new Date(startMonth + " " + startDay + ", " + startYear + " 00:00:00"); var startDayWeek = dayString(startDateISO.getDay()); if( allDay == true){ //change this to match your needs var str = [ '<font size="4" face="courier">', startDayWeek, ' ', startMonth, ' ', startDay, ' ', startYear, '</font><font size="5" face="courier"> @ ', item.summary , '</font><br><br>' ]; } else{ var time = dateTime[1].split(":"); //split hh ss etc... var startHour = AmPm(time[0]); var startMin = time[1]; var str = [ //change this to match your needs '<font size="4" face="courier">', startDayWeek, ' ', startMonth, ' ', startDay, ' ', startYear, ' - ', startHour, ':', startMin, '</font><font size="5" face="courier"> @ ', item.summary , '</font><br><br>' ]; } li.innerHTML = str.join(''); li.setAttribute('class', classes.join(' ')); document.getElementById('events').appendChild(li); } document.getElementById('updated').innerHTML = "updated " + today; document.getElementById('calendar').innerHTML = calName; }); }); } //--------------------- end </script> <script src='https://apis.google.com/js/client.js?onload=handleClientLoad'></script> <div id='content'> <h1 id='calendar' style="color:grey">LOADING . . . .</h1> <ul id='events'></ul> </div> <p id='updated' style="font-size:12; color:grey">updating . . . . .</p> </body> </html> 

這幾乎可以解決我的問題,但是我想知道是否要從與要從中提取信息的日歷相關聯的電子郵件地址發送電子郵件,是否可以避免使用“ var clientId”和“ var apiKey”? 還是有資源說明如何安全地使用此代碼?

如果您創建Apps腳本代碼,則可以避免使用clientID和API密鑰,共享的代碼是創建Web應用程序,因為它在Google Services外部,因此需要clientId和API密鑰。

有關Google Apps腳本的更多詳細信息,可以檢查https://developers.google.com/apps-script/https://developers.google.com/apps-script/reference/calendar/以獲取日歷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM