2017-01-20 1 views
0

나는 마지막 전자 메일 스레드 CSV 첨부 ID를 얻으려고하지만 코드를 작성하는 데 어려움을 겪고 있습니다. 누구든지 도울 수 있니?스레드에서 마지막 전자 메일 가져 오기 및 CSV 첨부 파일 가져 오기

var searcher = "Automail-"+CurrentDateFormat+".csv"; 

var searchedThreads = GmailApp.search('subject:""'+searcher+'""')[0]; 

var id = searchedThreads.getId(); 
var dateMessage = GmailApp.getMessageById(id).getDate(); 
var contentmessage = GmailApp.getMessageById(id).getPlainBody(); 

var attachtextLength = GmailApp.getMessageById(id).getAttachments()[0].getDataAsString().length; 
if (attachtextLength >= 150){ 

var attachtext = GmailApp.getMessageById(id).getAttachments()[0].getDataAsString(); 

UpdateSheet(attachtext); 
+0

어떤 어려움이 있습니까? 어떤 오류가 발생합니까? –

+0

코드는 현재 첨부 파일을받을 수 있지만 마지막 전자 메일이 아닌 첫 번째 전자 메일에서만 제공됩니다. –

+0

그럼 어떻게됩니까? 디버깅 문을 삽입하여 다양한 변수의 값을 확인하십시오. 두 번째 이메일에서 다른 정보를 가져 오거나 전혀 가져올 수 없습니까? –

답변

1

여러 스레드의 일치하는 마지막 스레드를 찾고 있다면 ....

var searchedThreads = GmailApp.search('subject:""'+searcher+'""'); 
searchedThreads = searchedThreads[searchedThreads.length-1]; 

마지막 첨부 파일을 찾고 있다면 ....

var attachtext = GmailApp.getMessageById(id).getAttachments(); 
attachtext = attachtext[attachtext.length-1].getDataAsString(); 

희망 도움이됩니다.

+0

매력처럼 일했습니다, 건배 –