I am trying to send email with attachment (zip file). I managed to do so, but now my main problem is that I need code to get access_token, if I try GET request to get the code
https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize?client_id={clientId}&response_type=code&redirect_uri=https%3A%2F%2Flocalhost&response_mode=query&scope=offline_access%20Mail.ReadWrite%20Mail.send&state=111111
I get error saying that I need to sign up, that's a problem because I can't do so from my app.
I tried this method I found
{
client_id: clientId,
scope: 'https://graph.microsoft.com/.default',
grant_type: 'client_credentials',
client_secret: clientSecret,
}
and I get access token but I cannot send a mail with video with that access token as I get http 401, my app has these permissions Mail.ReadWrite, Mail.Send, User.Read
I registered one Entra ID application and granted
Mail.Sendpermission of Application type as below:Now, I generated access token using client credentials flow with below parameters:
Response:
You can decode the above token in jwt.ms website and check
rolesclaim for permissions:Using this access token, you can send the mail with attachments successfully like this:
Response:
Reference: user: sendMail - Microsoft Graph v1.0 | Microsoft