0

I want to make changes to the content of .msg file and save it back as .msg file(In the body of the message , I want to replace 'example.com' with 'replcement_text.com'). Not able to proceed further.

import extract_msg
folder = r"C:\Users\My_desk\Downloads\New folder"
with os.scandir(folder)as files:
    files = os.scandir(folder)
    for file in files:
        msg = extract_msg.Message(file)
        msg_sender = msg.sender
        msg_date = msg.date
        msg_subj = msg.subject
        msg_message = msg.body
  • 1
    Please [edit] to also put the sample contents of the input files, any error messages (Traceback), and any other information why output is not same as expected. – Gino Mempin May 15 '20 at 01:37
  • Assuming you are facing problems in manipulating `.msg` file, I would suggest using python libraries to do it. Please check the post [here](https://stackoverflow.com/questions/26322255) – ravi May 15 '20 at 02:13

1 Answers1

1

Use msg extractor to read the msg files and similar regex expressions to find and replace URL's.

Msg-extractor: https://pypi.org/project/extract-msg/

tersrth
  • 861
  • 6
  • 18
  • Thankyou for responding. Using the message extractor, I get this error- OSError: not an OLE2 structured storage file. I am trying to change the content of the .msg file which is stored locally in my system. Could you please help – user13513933 May 16 '20 at 22:49
  • i'm not too sure as i have only used msg extractor once before. could you try posting another question on s/o? – tersrth May 17 '20 at 02:52