I have been looking for a way to save all emails in the outlook of a particular day or from the start of the day to the time I run my program to my local folder using python. Is there any way we can do this?
Asked
Active
Viewed 372 times
0
-
Got what i was looking for! Please refer to this post. https://stackoverflow.com/questions/51621535/saving-email-from-outlook-into-folder-with-python – Rishab S Nov 25 '21 at 10:25
-
1Does this answer your question? [Saving email from Outlook into folder with Python](https://stackoverflow.com/questions/51621535/saving-email-from-outlook-into-folder-with-python) – Patrick Nov 29 '21 at 16:22
1 Answers
0
Something along these lines, I believe, would be an excellent starting point:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(r"C:\test_msg.msg")
print msg.SenderName
print msg.SenderEmailAddress
print msg.SentOn
print msg.To
print msg.CC
print msg.BCC
print msg.Subject
print msg.Body
count_attachments = msg.Attachments.Count
if count_attachments > 0:
for item in range(count_attachments):
print msg.Attachments.Item(item + 1).Filename
del outlook, msg
snippet of code comes from another thread see below
Refer to Brent Edwards's answer for more details.
Note: If you won't use Outlook client you could do as follow: https://stackoverflow.com/a/49681576/9814037

Simon Provost
- 356
- 1
- 2
- 15
-
Hey, Appreciate the answer. But instead of writing the contents, is there a way we can just save the email as it is? Consider it as if we are copying an email from the inbox to our local machine. – Rishab S Nov 25 '21 at 09:06
-
With Python, you can save the content of the body (for instance) to a file such as a csv or whatever you want? Refer to this quick introduction: https://www.w3schools.com/python/python_file_write.asp – Simon Provost Nov 25 '21 at 09:09
-
-
Hey, I have posted what I was looking for. It was saving the info in the email format, please refer to the link above in my answer. But thank you for the effort, appreciate it a lot. – Rishab S Nov 30 '21 at 10:01