[英]Get email from Google Docs
我實際上想每天發送 MoM,所以我創建了一個文件夾,其中放置了所有 MoM 文檔,並以創建日期為它們命名。 然后腳本在當天讀取它並將其發送到固定的 email 地址,但現在我們將參與者插入到谷歌文檔中,如下所示:-
有什么辦法可以得到那里提到的那些 email 地址/用戶 email 地址。
我之前使用的腳本是這樣的:-
function sendMinutes() {
const folder = DriveApp.getFolderById('Filder id')
const today = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM dd,yyyy')
const files = folder.searchFiles(`title contains '${today}'`)
while(files.hasNext())
{
let file= files.next()
let doc = DocumentApp.openById(file.getId())
let body = doc.getBody()
let parag = body.getParagraphs().forEach(r=> {
.....
})
}
}
我知道如何獲取 email 但是,它現在只是返回第一個 email,我需要將每個 email 地址作為 ElementType 作為 PERSON:-
body.findElement(DocumentApp.ElementType.PERSON).getElement().asPerson().getEmail()
謝謝
Body.findElement
有幾個forms,其中一個使用兩個參數,第二個是尋找下一個元素的起點。 將此方法表單與循環一起使用。 在以下示例中,使用了while
語句:
function logEmailsFromPersonChips() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
let found;
const emails = [];
while ( found = body.findElement(DocumentApp.ElementType.PERSON,found)){
const email = found.getElement().asPerson().getEmail();
emails.push(email);
}
console.log(JSON.stringify(emails))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.