문제

GAS에 저장된 일부 전자 메일을 마이그레이션하기 위해 Google Drive를 작성하려고하지만 정말로이 작업을 수행하기 위해 게시물을 정확하게하기 위해 고심하고 있으며 누군가가 나를 도울 수 있고 올바른 방향으로 나를 조종 할 수 있기를 바랍니다.

지금까지 가지고있는 것은 ..

  var id = "12345678abcdefgh";
  var doc = DocumentApp.openById(id);
  var emlData = doc.getText();
  var api_scope = 'https://www.googleapis.com/auth/email.migration';
  var app_name = "migration";
  var userKey = "someone@mygappsdomain.com";
  var method = "POST";

  var url = "https://www.googleapis.com/upload/email/v2/users/"+userKey+"/mail?uploadType=multipart";


  var fields =  {"MailItem" : 
                  {"properties":
                   {'isInbox': 'true','isUnread': 'true'},
                   'labels': ['MigrateMe']}};

  var options = {payload: {data: JSON.stringify(emlData), fields: fields, contentType: 'multipart/related', boundary : 'part_boundary'}};
  var fetchArgs = googleOauth_(app_name,api_scope,method,options);
  try
  {
    var result = UrlFetchApp.fetch(url, fetchArgs).getResponseCode();
    Logger.log("done");
  }
  catch (ee) 
  {
    Logger.log(ee);
  }
}
.

이것은 분명히 작동하지 않으며 400 오류 코드를 얻습니다.당신은 무엇이 잘못 될 수 있는지 아십니까?

도움이 되었습니까?

해결책

댓글의 음성이있는 것처럼 여기에서 놀이터 API와 함께 할 수있는 기분 :

1 단계 :
권한 부여 : https://www.googleapis.com/auth/email.gration <. / P>

2 단계 :
BLBBABLABLABLA 인증 (여기에서해야할 사항을 알고 있음)

3 단계 :
HTE URL에 게시물을해야합니다. https://www.googleapis.com/upload/email/v2/users/ <. / aa>
/mail

콘텐츠 형식을 설정해야합니다 : 사용자 정의 ...
인수는 다음과 같습니다.

uploadType:media
Content-Type:message/rfc822
.

요청 본문은 다음과 같이보아야합니다 :

Date: Wed, 03 Jan 2013 02:56:03 -0800
From: admin@example.org
To: liz@example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit

And I think to myself... What a wonderful world!
.

(이 하나는 일부 테스트를 수행하고 "Liz"에 대한 사서함 검색에서 사서함을 검색 할 수 있습니다.

모든 것이 작동하면 다음과 같이해야합니다. 여기에 이미지 설명

여기에서 찾은 설명서를 사용했습니다. https://developers.google.com/admin-sdk/ 이메일 이주 / v2 / 가이드 / 업로드
https://developers.google.com/admin- SDK / 이메일 이주 / v2 / 참조 / 메일 / 삽입

이것은 귀하의 게시물의 해결책이 아니지만, 당신이 그것을 얻는 데 도움이되기를 바랍니다! (그리고 그런데 멋진 작업 코드를 갖게되면 질문에 대한 진짜 답변을주십시오 - 또한 관심이 있습니다.

다른 팁

스크립트

나는 자유 의견을 재건하기 위해 자유를 맡았습니다. 귀하의 의견의 차이점 :

var template = HtmlService.createTemplateFromFile("MailTemplate");
template.sentDate = "Wed, 04 Mar 2014 02:56:03 -0800";
template.from = "sender.address@blahblah.com";
template.to = "recipient.address@blahblah.com";
template.subject = "second test";
template.body = "I was migrated via script !!!!";
template.sentDate = eml_sentDate;
template.from = eml_from;
template.to = eml_to;
template.subject = eml_subject;
template.body = eml_body;
var emlData = template.evaluate().getContent();
var api_scope = 'googleapis.com/auth/email.migration';;
var app_name = "migration";
var userKey = "recipient.address@blahblah.com";
var method = "POST";

var url = "googleapis.com/upload/email/v2/users/" + userKey + "/…"; 
var options = { method : 'POST', contentType: 'message/rfc822', uploadType: 'media', payload: emlData };


var fetchArgs = googleOauth_(app_name, api_scope, method);
fetchArgs.payload = emlData;
fetchArgs.contentType = 'message/rfc822';
fetchArgs.uploadType = 'media';
var result = UrlFetchApp.fetch(url, fetchArgs).getResponseCode();
.

멀티 파트

듀얼 멀티 파트를 제공 할 수있는 작업 : Google API에 배치 요청을 수행하는 데 전념하는 스크립트의 일부입니다 (Google 그룹에 사용자를 추가하도록 설계되었습니다).배치는 다중 인쇄 파일을 통해 수행되어 메일보다 훨씬 똑같습니다.

function batchRequest(userArray,grpEmail){
  var grpEmail = grpEmail || "testgroup@domain.ext";
  //var postUrl = "https://www.googleapis.com/admin/directory/v1/groups/"+grpEmail+"/members";
  var postUrl = 'https://www.googleapis.com/batch';
  var accessToken = refreshAccessToken();
  var userEmail = ""
  var boundary = 'batch_foobarbaz';
  var  payload = "";

  for(var i in userArray){
  payload+= '--'+boundary+'\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\n';
  payload+='POST /admin/directory/v1/groups/'+grpEmail+'/members HTTP/1.1\n';
  payload+= 'Content-type: application/json\n\n';
  payload+='{"email": "'+userArray[i]+'", "role": "MEMBER"}\n';
  }
  payload+='--'+boundary+'--';

   var params={
     method:'POST',
    contentType:'multipart/mixed; boundary="'+boundary+'"',
     headers:{
       Authorization:" OAuth "+accessToken  
     },
      payload:payload,
     muteHttpExceptions:true
   }
  var requestResponse = UrlFetchApp.fetch(postUrl, params);
  var result = requestResponse.getContentText();
  Logger.log(requestResponse.getResponseCode()+" - "+result);
  return(requestResponse.getResponseCode());

}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top