How to read emails from Microsoft Exchange email?

Hello,

I am trying to create custom plugin which will get emails from Microsoft Exchange mail and forward it to the Event Console.

Shortly:
I am using Check Mk 1.2.8p21 Raw
For my script I am using Python 2.7 and exchangelib
Server - Centos 7

My script:

import smtplib
from datetime import datetime, timedelta
import re, os
from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, FaultTolerance,
EWSDateTime, EWSTimeZone, Configuration, NTLM, GSSAPI, CalendarItem, Message,
Mailbox, Attendee, Q, ExtendedProperty, FileAttachment, ItemAttachment,
HTMLBody, Build, Version, FolderCollection

credentials = Credentials(
username=‘email@test.com’,
password=‘password’)

config = Configuration(retry_policy=FaultTolerance(max_wait=3600),
server=‘outlook.office365.com’, credentials=credentials)

account = Account(
primary_smtp_address=‘email@test.com’,
config=config,
autodiscover=False,
access_type=DELEGATE)

for item in account.inbox.all().order_by(’-datetime_received’)[:5]:
item.subject
item.sender
item.datetime_received

The above code is working perfectly in Pycharm.

My question is.
Did someone already faced with my problem? If the answer is yes, can you give some advice or share your code? If you know plugin which do the same thing, please share link.

Thanks,
Georgi

Hi Georgi,

please describe your problem more in detail. Even if i could help you,
right now i don’t your problem you’re failing to solve.

If the problem is @Microsoft Exchange itself, then you’re in the wrong forum :wink:
Greets
Kruzgoth

Hello again,

Basically I have to monitor system through emails. The system is configured to send emails when specific thresholds are reached. The emails are send to outlook mail. The email where those emails are received is Microsoft Exchange.

I checked Check Mk for check that might help me achieve it and found Check Email. The problem is that this check is not applicable to my scenario. After searching in internet and consultation with a friend I concluded that the problem comes from mail I am trying to access. It is not possible to use gmail, due to Corporate restrictions.

I searched again and I found about exchangelib and wrote small script which allows me to read the emails.

I trying to find out plugin that allows you to log in to Microsoft Exchange email, get all emails and forward them to the Event Console as like Check Email doing.