A cloud-based identity and access management service for securing user authentication and resource access
@Ibrahim Mufti
The most likely cause of the 401 Unauthorized error, even with the correct scopes, is that the user account you are authenticating with does not have an active Microsoft 365 license with an Exchange Online mailbox.
The /me/sendMail API endpoint requires a user to have a functioning mailbox to send emails. An Exchange Online mailbox is only created when a user has a license that includes this service. The scopes (Mail.Send, Mail.ReadWrite, etc.) grant your application the permission to act on the user's behalf, but the user themselves must have the underlying capability to send mail.
This is a common point of confusion. While your authentication and token are correct, and the token contains all the necessary permissions, the 401 error is not about your application's permissions; it's about the user's lack of a licensed mailbox.
Since you mentioned you don't have a Microsoft 365 license and don't qualify for the developer program, the account you're using for testing likely doesn't have an associated mailbox, which is a hard requirement for the sendMail functionality.
I hope this helps in resolving the issue, do let me know if you have any further questions on this