I am using Google Apps Script (*.gs) to send mail via Gmail. Mails are working file and even attachments using images available in public URL are working fine. I am using
var file = DriveApp.getFileById("Google file ID")
to get the file and attach. I am getting the error
The feature you are attempting to use has been disabled by your domain administrator.
I am the admin and want to understand exactly where do I enable this feature. Can someone guide me please.
Addtionally, I checked my Google script Code's project properties and found that the following 4 OAuth Scopes are required by the script: Here are the scopes and next to them the response when I try accessing these in my browser.
Here are 3 scenarios I have tried. the 3rd one fails.
function SimpleMail(){
GmailApp.sendEmail(<recipient email>, 'MAIL without any ATTACHMENT',
'Hi, \nPlease see mail without any attachment' )
}
function sendAttachment(){
var attachmentUlr = "<URL of an Image on a public facing website>" ;
var fileBlob = UrlFetchApp
.fetch(attachmentUlr)
.getBlob()
.setName("fileBlob"+'.jpg');
GmailApp.sendEmail(<recipient email>, 'MAIL with ATTACHMENT',
'Hi, \nPlease see mail with image from a website as attachment', {attachments:[fileBlob]})
}
function sendAttachment(){
var attachmentUlr = DriveApp.getFileById('<Google File ID>');
var fileBlob = UrlFetchApp
.fetch(attachmentUlr)
.getBlob()
.setName("fileBlob"+'.xlsx');
GmailApp.sendEmail(<recipient email>, 'MAIL with ATTACHMENT',
'Hi, \nPlease see mail with file from Drive as attachment', {attachments:[fileBlob]})
}
The issue got resolved once I enabled Drive SDK API as an admin. Got to admin panel > Apps > G Suite > Settings for Drive and Docs > Features And Applications. Enable / Check on the box - "Allow users to access Google Drive with the Drive SDK API".
Once this setup was enabled, my code was able to pick the file from google drive for attachment.