Download Outlook Email Attachments Using Microsoft Graph API In Python

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

КОМЕНТАРІ • 68

  • @albinrdz1432
    @albinrdz1432 Рік тому +5

    to those who have problems with the downloaded files, 1kb or if it is corrupt file, the problem is Jie forgot to add ,headers=headers in line 17.
    attachment_content = requests.get(
    GRAPH_API_ENDPOINT + '/me/messages/{0}/attachments/{1}/$value'.format(message_id, attachment_id),
    headers=headers
    )

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

    the attachments remain as corrupted files, I can't find a solution to this, did it happen to you?

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

      to those who have problems with the downloaded files, 1kb or if it is corrupt file, the problem is Jie forgot to add ,headers=headers in line 17.
      attachment_content = requests.get(
      GRAPH_API_ENDPOINT + '/me/messages/{0}/attachments/{1}/$value'.format(message_id, attachment_id),
      headers=headers
      )

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

    How can we set up the orderby param? For example, if I want to sort emails by receivedDateTime desc, how would I set up the string corresponding to that param?

  • @tridibbiswas3361
    @tridibbiswas3361 2 роки тому

    Thank you for the video. What’s the theme and font you are using.

    • @jiejenn
      @jiejenn  2 роки тому

      Hey Tridib, glad the video helped. I am using VS Code with Dark Pro color theme with my own color theme customization.

  • @ashwinks2965
    @ashwinks2965 2 роки тому

    Thanks a lot for the Video👏. Very Useful one. But I am getting exception.
    Exception: {'error': {'code': 'Request_BadRequest', 'message': "Unrecognized query argument specified: 'top,select,filter,count'.

    • @jiejenn
      @jiejenn  2 роки тому

      As the error states, your query is incorrect.

  • @TT-hl3sm
    @TT-hl3sm 2 роки тому +1

    Hi Jenn, thank you very much for the video. I was able to generate a token and download files with different extensions, however, when you open the downloaded attachments they only have the following: {"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty."}. Any help would be appreciated!

    • @jiejenn
      @jiejenn  2 роки тому

      Without looking at your script, I can only guess there could be a typo somewhere.

    • @TT-hl3sm
      @TT-hl3sm 2 роки тому

      @@jiejenn Thank you very much for the response! To make sure that there are no typos I tried copying code from your links above. The only change I made is APP_ID and the folder where the attachments need to be saved. I am getting the same error- "Access token is empty." The attachments are saved with different extensions, but they only contain the same error message. Thank you, Jie Jenn!

    • @rohanm9662
      @rohanm9662 2 роки тому +2

      @@TT-hl3sm try adding ,headers=headers in line 17

    • @TT-hl3sm
      @TT-hl3sm 2 роки тому

      @@rohanm9662 Thank you, Rohan. I actually tried the proposed modification. August 23, 2022 I was getting an error ":{"code":"BadRequest","message":"Resource not found for the segment 'messages'."} , September 5, 2022 error ":{"code":"ResourceNotFound","message":"Invalid version: v1.0me"}.

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

      @@TT-hl3sm same problem for me i also can't open the attachments if u clear this say how to do

  • @sarveshsinha8188
    @sarveshsinha8188 2 роки тому

    Thanks for the video it really helped alot. I am looking for solution to mark mail as read after reading it using graph api.

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

    what is the maximum size of attachment that we can fetch from the Graph API endpoint ?

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

    Thanks for this. I am getting the following error in the flow variable: "No tenant-identifying information found in either the request or implied by any provided credentials". I'm assuming this means it wants me to pass the tenantID but I don't think generate_access_token() is set up for that. Any ideas?

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

      I got the same response, did you manage to find a fix since?

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

    Thanks Jie Jenn
    I was able to download the attachments but it seems their size is 1kb and not able to open them

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

      Hard to tell without looking at your script.

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

      I had same problem as you and debugged to find out that the response code for attachment_content was 401 which is unauthorized response although I already authenticated. However I forgot to add in the headers (where the access_token is stored) in the get request. It worked after adding headers = headers in the get request

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

      same with me , all files are of 1 kb , and its opening for me.

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

      to those who have problems with the downloaded files, 1kb or if it is corrupt file, the problem is Jie forgot to add ,headers=headers in line 17.
      attachment_content = requests.get(
      GRAPH_API_ENDPOINT + '/me/messages/{0}/attachments/{1}/$value'.format(message_id, attachment_id),
      headers=headers
      )

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

    How can I extract an email body and subject line from a specific user?

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

    Can the graph API help in extracting the whole email as a html file

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

      Sure. response can be in either HTML or text format.

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

      @@jiejenn thanks;

  • @vickey8709
    @vickey8709 2 роки тому

    Hi Jenn,
    Thanks it's very helpful!
    I want to download attachments from a specific sender with some specific subject line. After that want to upload those attachments to aws s3 buckets without downloading into local.. could please help me to update with the modified code. Would be helpful.
    Thank you

    • @jiejenn
      @jiejenn  2 роки тому

      Hi Vickey, your request is quite specific. I would post your question on Stack Overflow for assistance.

    • @vickey8709
      @vickey8709 2 роки тому

      @@jiejenn Thank you

    • @bharathikannan5772
      @bharathikannan5772 2 роки тому

      @@vickey8709 Hi Vickey, did you get the solution for this

    • @manojm2099
      @manojm2099 2 роки тому

      Hi Vickey, Were you able to find the solution? If yes, could you please share me that

  • @gautami5934
    @gautami5934 2 роки тому

    Thanks a lot for the video. Can you please help me to export contact photos. I want to use Patch or Put request.

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

    hi i want to specific an email address and download the pdf attachment can i use the same cod ?

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

      If you want to use specific email address, replace /me/ with /users/.

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

      @@jiejenn thnx but if u can help im getting this error {"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError"

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

      You might have to Google it.

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

      @@jiejenn thnx for your help

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

    Could you please make video on retrieve MS Teams chat in python?

    • @jiejenn
      @jiejenn  5 місяців тому +1

      I will look into it.

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

      @@jiejenn Thank please make it as soon as possible it will really helpful..there is not a single video on UA-cam on this topic.
      With the chat data we can perform various tasks with python libraries 🔥

  • @parvindersingh
    @parvindersingh 2 роки тому

    Which user's mailbox is this app id linked to?

    • @jiejenn
      @jiejenn  2 роки тому

      To whichever account you authenticated.

  • @sebastianeyzaguirre8394
    @sebastianeyzaguirre8394 2 роки тому

    Does it still hold if an email has multiple attachments?

    • @jiejenn
      @jiejenn  2 роки тому

      What do you mean? The video is showing how to download multiple attachments already.

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

    Is there a way to download .eml attachment using graph API ?

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

      You should be able to down any file format.

  • @NP-zg3hq
    @NP-zg3hq Рік тому

    Can we download the messege itself in .msg format?

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

      Msg file is specific to Windows Outlook. Are you on a Windows PC?

    • @NP-zg3hq
      @NP-zg3hq Рік тому

      @@jiejenn yes, outlook with office 365 account

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

      @@NP-zg3hq Because msg is specific to Windows Outlook application, you will have to use VBA to export emails as msg files.

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

    how do you get the message ID?

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

      You can use the message list method.

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

    how do i find emails with specific text?

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

      Not sure if I understand your question.

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

      @@jiejenn searching the inbox for specific words in the subject line

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

      how can i make the script download attachment only from a specific sender@@jiejenn

    • @GraceZhang-oo5sf
      @GraceZhang-oo5sf 11 місяців тому

      I can download my outlook attachments with specific subject and then rewrite the attachment file name with current day, but i not sure can do this in api@@TmanD54

  • @jiejenn
    @jiejenn  2 роки тому +1

    Don't know where your app id is? please refer to this video ua-cam.com/video/1Jyd7SA-0kI/v-deo.html for instruction.

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

      Haha, thanks! Was asking God where that came from, but it seems like it was a scroll away! :)))

  • @Iva60571
    @Iva60571 2 роки тому

    Great video, thank you! However, the link to your site is not working :-(

    • @jiejenn
      @jiejenn  2 роки тому +1

      Thanks for letting me know. I must've changed something on my hosting yesterday. Fixing it right now...

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

    How to install ms_graph?

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

      You will have to create the module yourself. Source code is in the description.

  • @maribkhan3099
    @maribkhan3099 2 роки тому

    from where to get app id?

    • @jiejenn
      @jiejenn  2 роки тому

      You can refer to this video ua-cam.com/video/1Jyd7SA-0kI/v-deo.html