user459872
user459872

Reputation: 24974

How authentication works while reading outlook emails with python and win32com

I understood that we can read emails from outlook using the following code(Reading e-mails from Outlook with Python through MAPI).

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print body_content

But we are not providing username and password anywhere in the above code. Then How did the code authenticate the outlook account.

Can any one explain how the authentication is happening here.

Upvotes: 2

Views: 3237

Answers (1)

Megabeets
Megabeets

Reputation: 1408

win32com.client is interacting with Outlook COM object. Since Outlook is a singleton, you are actually spawning a "hidden" instance of Outlook. Remember that every time that you log in to Outlook you don't need to put username and password. This is why Username and Password are not required here as well.

Moreover, as long as the COM object of Outlook is opened, you won't be able to open Outlook through "exlporer". This is because only one instance of Outlook is allowed. You might notice that although you never opened Outlook's GUI, you still receiving the pop-up messages of new email.

Upvotes: 2

Related Questions