ドメインのすべてのメンバーと共有されている Google スプレッドシートがあります。ユーザーの 1 人がスクリプトを実行するたびに、スプレッドシートを電子メールの添付ファイルとして送信するスクリプトが必要です。
この質問をガイドとしてたどると、次のコードにたどり着きました。
function sendEmail() {
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getName();
//var email = Session.getUser().getEmail();
var email = "xxxxx@example.com";
var subject = "Order Form";
var body = "Please find the attached Order Form for drop-ship delivery.";
var oauthConfig = UrlFetchApp.addOAuthService("google");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://spreadsheets.google.com/feeds/");
oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
var requestData = {"method": "GET", "oAuthServiceName": "google", "oAuthUseToken": "always"};
var url = "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="
+ ssID + "&gid=0&portrait=true" +"&exportFormat=xls";
var result = UrlFetchApp.fetch(url , requestData);
var contents = result.getContent();
MailApp.sendEmail(email,subject ,body, {attachments:[{fileName:sheetName+".xls", content:contents, mimeType:"application//xls"}]});
}
このコードは機能しますが、最初にスクリプト エディターからコードを実行し (これには、Google メール アカウントへのアクセスを承認する必要があります)、スクリプトを使用するときにスクリプトを承認する必要があります。
そのため、このドキュメントを注文部門に渡しましたが、これも、各ユーザーがスクリプト エディターからスクリプトを承認し、使用時にスクリプトを承認した場合にのみ機能します。
「スクリプトエディタによる認証」をなくす方法はありますか? このスクリプトを承認するために各ユーザー アカウントにアクセスする必要はありません (また、作成された新しいユーザーに対して同じことを行うことを忘れないでください)。
提供されたヘルプに感謝します!