Hi @Palash Samanta
Thank you for reaching out to the Microsoft Q&A forum!
I understand you're encountering a 401 error when running your script using the Microsoft Graph API Send Mail endpoint
Based on the code you shared, I noticed that the sender's email address uses a @gmail.com domain, which is not supported by Microsoft Graph. Microsoft Graph is designed to work only with Microsoft 365 services. This means the User Principal Name (UPN) of the sender must belong to a domain that has been added to your Microsoft 365 tenant and must have an active mailbox license.
Reference:
If you intend to send emails from a @gmail.com address, I recommend using the Gmail API, which is the appropriate endpoint for that service. You can find more details in the official documentation here: https://developers.google.com/gmail/api/guides/sending
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
I sincerely hope this information partially clarifies your situation and assists you in planning your solution. Please do not hesitate to reply if you have any updates.
Thank you for your understanding.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.