电子邮件迁移API v2:Google Apps脚本 [英] Email Migration API v2: Google Apps Script
问题描述
我正尝试编写 GAS
来迁移存储在 Google云端硬盘
中的一些电子邮件,但我确实努力让POST正确地做到这一点,并希望有人能帮助我,并引导我朝着正确的方向前进。
到目前为止, p>
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);
尝试
{
var result = UrlFetchApp.fetch(url,fetchArgs).getResponseCode();
Logger.log(done);
}
catch(ee)
{
Logger.log(ee);
$ / code $ / pre
这显然不起作用,我得到了400错误代码。你知道什么可能是错的吗?
解决方案正如在评论中所说的一个例子,第1步:
$ b 授权:
https://developers.google.com/admin-sdk/email-migration/v2/reference/mail/insert
这不是解决方案你的帖子,但我希望它会帮助你得到它! (顺便说一下,如果你有一个很好的工作代码,请给出你的问题的真实答案 - 我也感兴趣)
I am trying to write a GAS
to migrate some emails which are stored in Google Drive
but I am really struggling to get the POST correct to do this and was hoping someone could help me out and steer me in the right direction.
What I have so far is ..
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);
}
}
This obviously doesn't work and I get a 400 error code. Do you know what could be wrong ?
解决方案 As spoken in comment here an exemple to do it with the playground api:
step 1:
Authorise: https://www.googleapis.com/auth/email.migration
step 2:
Authorize blbablablabla (you know what to do here)
step 3:
You need to do a POST to hte URL:
https://www.googleapis.com/upload/email/v2/users/EMAILADRESS@DOMAIN.EXT/mail
The Content-type need to be set on: custom...
and the arguments are:
uploadType:media
Content-Type:message/rfc822
the request body must look at something like this:
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!
(you can take exactly this one to do some test and then in your mailbox search for "liz")
If everything worked you should have something like this:
To do this I used the documentation found here:
https://developers.google.com/admin-sdk/email-migration/v2/guides/upload
https://developers.google.com/admin-sdk/email-migration/v2/reference/mail/insert
This is not the solution to your post, but I Hope it will help you to get it! (and by the way if you get to have a nice working code please give the real answer to your question - I'm also interested)
这篇关于电子邮件迁移API v2:Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!