I am using the Gmail API to create drafts. When I create a draft message where the recipient is my own email (the one that generates the credential), everything works fine but when I try to use a different email, the following message is printed:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Delegation denied for [email protected]",
"reason" : "forbidden"
} ],
"message" : "Delegation denied for [email protected]",
"status" : "PERMISSION_DENIED"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
That's how I'm assembling my MimeMessage
:
val props = Properties()
val session = Session.getDefaultInstance(props, null)
val message = MimeMessage(session)
message.setFrom(message.sender)
message.addRecipient(JavaxMessage.RecipientType.TO, InternetAddress("[email protected]"))
message.subject = subject
The scopes I am using:
// "https://www.googleapis.com/auth/gmail.compose"
GmailScopes.GMAIL_COMPOSE
I've tried a lot of stuff to make it work, but I didn't have any success.