How To Download Email Attachments in Office 365 Mailbox Using Python And Microsoft Graph API

Поділитися
Вставка
  • Опубліковано 26 жов 2024

КОМЕНТАРІ • 34

  • @motuada
    @motuada 4 місяці тому

    It helped a lot! I had problems at the beginning because I was filtering a specific message. I removed it from the filter and it worked for all messages. I also applied the Base64 tip. Thank you for sharing.

  • @djosue27
    @djosue27 3 місяці тому

    Absolutely amazing! Even MS Documentation doesn't illustrate this as easily

  • @scott5957
    @scott5957 Рік тому +2

    Insanely helpful video - can not thank you enough! Been banging my head against a wall for weeks trying to get this to work and this video finally made it happen. Only thing I did have to adjust at the end when you are setting the “download_attachment_endpoint” it needs (or mine did at least) a “/$value” at the end of that variable so I would get the actual file contents rather than just another JSON string. So helpful - thank you again!

    • @letsplay8389
      @letsplay8389 Рік тому +2

      Thanks scott5957, this fixed the unreadable files issue others have been noting.

    • @rahulshah1408
      @rahulshah1408 5 місяців тому

      Thank you. That was my other missing puzzle piece.

  • @gabrielef3336
    @gabrielef3336 4 місяці тому +2

    It's a great tutorial but in the last step you miss to convert the content of the response before witing the file.
    This could be a way (import base64):
    attachment_content = response.json()['contentBytes']
    decoded_content = base64.b64decode(attachment_content)
    # Save the file
    with open(attachment_name, 'wb') as file:
    file.write(decoded_content)
    file.close()
    Bye

    • @cmetzger4
      @cmetzger4 2 місяці тому

      Thank you so much for adding this extra bit! I was pulling my hair out

  • @CLGFM
    @CLGFM Рік тому

    Finally able to read my mailbox emails, the other tutorials show you only to oauth via browser to authenticate which is useless for service scripts. Thank you.

  • @svgenterprises1
    @svgenterprises1 Рік тому

    This was extremely valuable in understanding how to work with the Graph API! Thank you so much for this content.

  • @rahulshah1408
    @rahulshah1408 5 місяців тому

    Thank you for the step by step. I am new to python (former database admin with zero coding) and am having to google each line of code I am writing. This has been amazing. out of convenience, do you have a google drive or public github to access the code example?

  • @sheepinriver
    @sheepinriver 8 місяців тому

    Really helpful !! Just wondering does that Mail.Read permission allow read all user mailboxes ? That is the permission very very hard to get unless you are an IT administrator.

  • @xFree23Stylex
    @xFree23Stylex 7 місяців тому

    Thank you for your help!

  • @Nova04550
    @Nova04550 7 місяців тому

    I think that's giving app permissions to every mailbox! Probably best to use delegated permissions and then authenticate on behalf of a user.

  • @TanveerKhizar
    @TanveerKhizar Рік тому +1

    getting KeyError: 'value' for line 54
    for attachment in attachments['value']:

  • @MrArjunrajan
    @MrArjunrajan 11 місяців тому

    I am getting an error as "/me request is only valid with delegated authentication flow." during subscription call.

  • @cristhiansevilla4091
    @cristhiansevilla4091 11 місяців тому

    when I tried to run the code, this message return {'error': {'code': 'ErrorAccessDenied', 'message': 'Access is denied. Check credentials and try again.'}}

  • @magueritemichima6818
    @magueritemichima6818 7 місяців тому

    hello Sir , great video , how can i get the code ?

  • @hemanthbanty6187
    @hemanthbanty6187 Рік тому

    How to download the file to specific folder path rather than the script place.

  • @srp9819
    @srp9819 Рік тому

    why are you not getting a option on the browser to authorize the graphApi ,
    is there a way to by pass that , so that we can run the script any time with a scheduler , without any intervention ?

    • @bernardmwanza1628
      @bernardmwanza1628  Рік тому +1

      my script does not have that browser auth thing, once you have the app secret, appclientid and tenantid hardcoded in the script, you can schedule it using windows task manager

    • @RohitKumar-yz3eo
      @RohitKumar-yz3eo Рік тому

      Can you please tell how to do that

  • @JonathanDuque-d5z
    @JonathanDuque-d5z Рік тому +1

    I get unreadable files

  • @abhilashgaddam7836
    @abhilashgaddam7836 Рік тому

    I am getting API response 403 what would I do?

    • @bernardmwanza1628
      @bernardmwanza1628  Рік тому

      that is a permission problem, you have not assigned your app registration correct permission to access the resources you are requesting.

    • @juanjoseospinaduque4524
      @juanjoseospinaduque4524 Рік тому

      @@bernardmwanza1628 Hello sir, at the moment i count all the permissions but im still getting this error "'message': 'Insufficient privileges to complete the operation", i need some special from de administrador o not? thx!

  • @momoViPRuS
    @momoViPRuS Рік тому

    you WOW

  • @vamsipreetham6224
    @vamsipreetham6224 Рік тому

    I am getting 401 error why this is coming

    • @bernardmwanza1628
      @bernardmwanza1628  Рік тому

      Your code. Is it correct

    • @vamsipreetham6224
      @vamsipreetham6224 Рік тому

      The same as your followed each step carefully but getting 401 error

    • @bernardmwanza1628
      @bernardmwanza1628  Рік тому

      Although 401 error is usually because of permission issue. Have u assigned and granted your app the correct application permission ?

    • @bernardmwanza1628
      @bernardmwanza1628  Рік тому

      You can test the code, step by step, first very if u can get the access token, then next verify if u can get the entire json response for a particular resource instead of the custom filtered one.

  • @SANDRO2464
    @SANDRO2464 Рік тому

    {'error': {'code': 'ErrorAccessDenied', 'message': 'Access is denied. Check credentials and try again.'

    • @Danips88
      @Danips88 8 місяців тому

      same mistake u.u

  • @manueltraverso1634
    @manueltraverso1634 Рік тому

    i get unreadable files