How to create the Service (like, local machine services) for the mail(outlook) tracking using Python. Email Tracking which means that I already add some configurations into the service. (like,I already give one of the subject name of the mail to the service).then it automatically running the service. When the same subject name of the mail comes, after that I want to read all those contents of the mail of same subject name and forward it to the another person. These all service Functionalities are done with the help of Microsoft Graph and python.Help me to How to do it!!!
Asked
Active
Viewed 414 times
-1
-
Welcome to Stack Overflow! Since you're new here, I recommend reading ["How do I ask a good question?"](https://stackoverflow.com/help/how-to-ask) for some tips. – Marc LaFleur Apr 26 '18 at 15:56
1 Answers
0
If you're able to use EWS instead of the Graph API, give exchangelib a try. Something like:
from time import sleep
from exchangelib import Account, Credentials
a = Account(
'john@example.com',
credentials=Credentials('user', 'pass'),
autodiscover=True
)
while True:
for m in a.inbox.filter(subject__contains='My Trigger', is_read=False):
m.forward(
subject='Fwd: My Trigger',
body='Hey, look at this!',
to_recipients=['carl@example.com']
)
m.is_read = True
m.save(update_fields=['is_read'])
sleep(60)

Erik Cederstrand
- 9,643
- 8
- 39
- 63
-
Is this code automatically creates Service After running the code? – Ben Kennadi Apr 26 '18 at 11:12
-
What do you mean by "service"? What do you want the service to do? I hardcoded the trigger and config values to simplify the example but you could pass them via the command-line if you want (see https://docs.python.org/3/library/argparse.html). – Erik Cederstrand Apr 26 '18 at 12:44
-
Service means its like a System service.Press Window Button -> type SERVICE -> Press Enter. After that you will see so many services which runs in background. It automatically running when the system on. My aim is to also create a service for automatic email tracking. That's why i'm asking – Ben Kennadi Apr 27 '18 at 04:08
-
Running a Python script as a Windows service is described here: https://stackoverflow.com/questions/32404/how-do-you-run-a-python-script-as-a-service-in-windows – Erik Cederstrand Apr 28 '18 at 07:00
-
exchangelib.errors.AutoDiscoverFailed: All steps in the autodiscover protocol failed – Ben Kennadi May 10 '18 at 10:22