-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_email.py
More file actions
47 lines (33 loc) · 787 Bytes
/
parse_email.py
File metadata and controls
47 lines (33 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# pip install win32com
import win32com.client
from os import walk
import re
#
# Get names of all messages in the folder
#
folderpath = "C:\\...\\"
f = []
for (dirpath, dirnames, filenames) in walk(folderpath):
f.extend(filenames)
#print(f)
#
# Open + Parse emails
#
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
for email in f:
#print(email)
try:
msg = outlook.OpenSharedItem(folderpath + email)
#print(msg.SenderName)
#print(msg.SenderEmailAddress)
#print(msg.SentOn)
#print(msg.To)
#print(msg.CC)
#print(msg.BCC)
#print(msg.Subject)
print(msg.Body)
#print(msg.Categories)
del msg
except:
print("can't open email")
del outlook