I am working on a Google Sheets add-on that calls Permissions: insert as described in a Stack Overflow answer:
function addUserPermission(fileId, email, notify) {
Drive.Permissions.insert({
'value': email,
'type': 'user',
'role': 'reader',
'withLink': false
},
fileId,
{
'sendNotificationEmails': notify
});
}
The notify flag is true if the user should receive an email notification of the added permission, false if they should not.
If the email value is associated with a Google account (such as foo@gmail.com), this works whether notify is true or false. If the email value is not associated with a Google account, an exception is thrown if notify is false:
ScriptError: GoogleJsonResponseException: API call to drive.permissions.insert failed with error: Bad Request. User message: "You are trying to invite fakeaddress@nowhere.com. Since there is no Google account associated with this email address, you must check the "Notify people" box to invite this recipient."
Is there any way to tell before calling Drive.permissions.insert that the email address is not associated with a Google account?