Error Message: Resource not found for the segment 'sendMail'
See original GitHub issueHi,
I think that I am missing something in the code, but I keep getting this error:
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://graph.microsoft.com/v1.0/sendMail | Error Message: Resource not found for the segment 'sendMail'.
Here is a snippet for the code:
def send_email(message, email, email_title, APP_CLIENT_ID, APP_CLIENT_SECRET, TENANT_ID):
print('Starting send_email function')
credentials = (APP_CLIENT_ID, APP_CLIENT_SECRET)
account = Account(credentials, auth_flow_type='credentials', tenant_id=TENANT_ID)
if account.authenticate():
print('Authenticated!')
m = account.new_message()
m.to.add(email)
m.subject = email_title
m.body = 'message'
m.send()
I’ve changed m.body to string in this snippet, since originally message variable stores MIMEMultipart value, which (according to another reported issue) is not supported. Could you please have a quick look and see if there is any issue in the code.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Getting error Resource not found for the segment while using ...
I wanted to Send email via graph API. I followed the documentation and Created a application in Azure Directory and got Admin Consent...
Read more >microsoft graph api - sendMail returns ResourceNotFound
I'm trying to send an email message using the Microsoft Graph REST API ... "ResourceNotFound", "message": "Resource could not be discovered.
Read more >[Solved] Resource not found for the segment in Power Automate
This will solve the error message Resource not found for the segment in Power Automate. The image below shows the value inputs without ......
Read more >getting an error "Resource not found for the segment...
Hi,. I am trying to send an email through ms flow. This ms Flow is triggering from the custom entity with help of...
Read more >I am receiving "Resource not found for the segment ...
However, when I am trying to download the same files through REST API, I am receiving error: {"error":{"code":"4a9b2a5d-a6c7-465c-b001- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, when using the client credentials auth flow, you are authentication with the app identity. So you will have access to all the resources the app has access to.
In order to send or read emails (or whatever action) you need to tell the library on who’s account you want to do this action. The app can’t guess it…
This is done using resources.
Following you example (and provided that your app has access to “example@example.com” account):
If you are going to do a lot of actions it’s better to use the mailbox so you define the resource just once:
Hi, This code is working for powershell and I am getting a valid token and able to send mail using Microsoft API and also I am able to get response from Postman.
User=“abc@.com” #User to be used for the delegated Permissions $PW=“******” #Password
The resource URI
$resource = “https://graph.microsoft.com” $clientid = “XXXX” #Application (client) ID from Azure App registration Page
$tokenBody = @{
Grant_Type = “password”
Scope = “user.read+openid+profile+offline_access”
Client_Id = $clientId
username = $User password = $pw resource = $resource }
Please help me to do in python script, I am using o365 library but I don’t know how to use it to create a connection with clientId,username and password. and also how I can set above those properties? I can’t find any examples of how to use delegated (“On behalf of a user”) access automatically.