Manvi
Manvi

Reputation: 1156

Get emails from intranet mailbox with Python on Linux system

I am able to access emails from company intranet mailbox 'ABCName.company.com' with my credentials username and password within outlook on my local system by setting it as different account.

Also, I am able to get automated emails with python code as below:

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder_inbox = outlook.Folders("ABCName").Folders("Inbox")
messages = folder_inbox.Items
message = messages.GetFirst()

How can I connect to same ABCName mailbox from linux server with my credentials to get the emails? Linux server do not have outlook setup.

Upvotes: 2

Views: 4372

Answers (1)

J. Davis
J. Davis

Reputation: 46

That code isn't connecting to a mail server. Outlook is a client-side email application that connects to a mail server and downloads messages using some protocol - IMAP, POP3, MAPI, etc. That code is simply reading the messages from the Outlook profile, which were already pulled off the server. Be aware that this code will not work on any other machines - including other Windows machines - without Outlook installed and configured for "ABCName" account.

Python runs on Windows and Linux, so assuming the script is configured correctly, it should run on either regardless of OS. You need an application that can read from a mail server, not a client-side email application. The modules you implement depend on protocols supported by the mail server.

For POP3, you can uses poplib:

https://docs.python.org/3/library/poplib.html

For IMAP, you can use imaplib:

https://docs.python.org/2/library/imaplib.html

Upvotes: 2

Related Questions