I want to create a json file with some information and send it to some mail with AppsScript.
var objeto = {update:[]};
var product = [];
//starting loop
for ( i = 0; i < 3; i ){
product.push({
id: i 1,
name: "prueba"
})
}
objeto.product = product;
Logger.log(JSON.stringify(objeto));
//DriveApp.createFile('New Json File', JSON.stringify(objeto), MimeType.JSON );
Some code here to create json file and send it to someone
CodePudding user response:
The createDraft
method takes an options
object as the 4th parameter.
One of the options is attachments
which takes an array of files.
This answer explains how to convert a string to a Blob in Google Apps script. Do that, put it in an array, then pass it to attachments
.
CodePudding user response:
Try this:
function lfunko() {
var objeto = { update: [] };
var product = [];
for (i = 0; i < 3; i ) {
product.push({
id: i 1,
name: "prueba"
})
}
objeto.product = product;
//Logger.log(JSON.stringify(objeto));
GmailApp.sendEmail("your email","Test",JSON.stringify(objeto));
}