Python Forum
Save image from outlook email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save image from outlook email
#1
So i have the following code that works great, updates my excel file and saves the file as expected.. BUT because we are merely updating the one excel file with the latest image, we are now wanting to archive the images when this script runs.

how can i modify this code to save off the image into the same folder with the date as the name so we can go back and look at past charts?

    # CHECK IF MESSAGE IS TODAY SO THAT THE MOST CURRENT SCREENSHOT IS UPDATED IN THE FILE.
    if edDate == tdDate:
        attachments = message.Attachments
        # THIS ENSURES THAT THE EMAIL HAS AT LEAST 2 ATTACHMENTS BEFORE IT TRIES TO DOWNLOAD FILES THAT DONT EXIST    
        if attachments.count >= 1:
            
            #LOOP THRU ALL ATTACHMENTS AND ONLY DOWNLOAD CSV FILES
            for att in attachments:
               p = Path(str(att).lower())
               
               newName = "{0}_{1}".format(p.stem,p.suffix)
               
               # CHECK IF ITS A PNG FILE BEFORE ATTEMPTING TO DOWNLOAD
               if p.suffix == ".png":
                  imgFileLoc = "C:\PricingVolume"+ '\\' + newName
                  # DOWNLOAD CSV FILE ONLY WITH THE NEW FILE NAME
                  figSaved  = att.SaveASFile(imgFileLoc)
                  #print(att)
                  # THIS IS THE MASTER EXCEL FILE THAT IS UPDATED AT THE END WITH THE FILTERED DATA
                  wrkb = openpyxl.Workbook()
                  ws = wrkb.worksheets[0]
                  img = openpyxl.drawing.image.Image(imgFileLoc)
                  img.height = 757
                  img.width= 1533
                  img.anchor = 'A1'
                  ws.add_image(img)
                  wrkb.save(PeakPricingVolumeFile)
Reply
#2
Disregard Big Grin

Not sure how to delete or mark this complete, i completely missed that the image was already being saved, just need to update to include the date in the name so we have daily image back ups.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 563 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Search Outlook Inbox for set of values cubangt 1 1,106 Jun-28-2023, 09:29 PM
Last Post: cubangt
  Looking to automate updating a spreadsheet with image from email cubangt 2 984 Feb-14-2023, 03:43 PM
Last Post: cubangt
  is it possible to copy image from email and place into excel file? cubangt 3 1,283 Nov-30-2022, 05:11 PM
Last Post: snippsat
  Mark outlook emails as read using Python! shane88 2 6,576 Feb-24-2022, 11:19 PM
Last Post: Pedroski55
  Trying out the parsing/reading of emails from my outlook cubangt 0 6,186 Jan-12-2022, 08:59 PM
Last Post: cubangt
  Help Needed | Read Outlook email Recursively & download attachment Vinci141 1 4,097 Jan-07-2022, 07:38 PM
Last Post: cubangt
  Need Outlook send email code using python srikanthpython 3 8,278 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  How to Save Full Email Body to CLOB in Oracle w/Carriage Returns? bmccollum 1 2,295 Mar-12-2020, 10:25 PM
Last Post: Larz60+
  reading shared outlook emails zarize 0 2,453 Mar-03-2020, 01:47 PM
Last Post: zarize

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020