使用 Python 连接到 Exchange 邮箱

2023-10-18Python开发问题
2

本文介绍了使用 Python 连接到 Exchange 邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要在 Python 脚本中连接到 Exchange 邮箱,而不使用本地计算机上的任何配置文件设置(包括使用 Outlook).如果我使用 win32com 创建 MAPI.Session 我可以使用现有配置文件登录(使用 Logon() 方法),但我只想提供用户名和密码.

I need to connect to an Exchange mailbox in a Python script, without using any profile setup on the local machine (including using Outlook). If I use win32com to create a MAPI.Session I could logon (with the Logon() method) with an existing profile, but I want to just provide a username & password.

这可能吗?如果是这样,有人可以提供示例代码吗?如果它只使用标准库和 pywin32 包,我会更喜欢.遗憾的是,无法为 Exchange 服务器启用 IMAP 访问(然后使用 imaplib).

Is this possible? If so, could someone provide example code? I would prefer if it only used the standard library and the pywin32 package. Unfortunately, enabling IMAP access for the Exchange server (and then using imaplib) is not possible.

如果有必要:所有脚本将做的就是连接到邮箱,并运行收件箱中的邮件,检索内容.如果我能首先获得连接,我可以处理为此编写代码!

In case it is necessary: all the script will be doing is connecting to the mailbox, and running through the messages in the Inbox, retrieving the contents. I can handle writing the code for that, if I can get a connection in the first place!

澄清有关 Outlook:Outlook 将安装在本地计算机上,但它没有任何帐户设置(即所有适当的库都将可用,但我需要独立于 Outlook 内部的任何设置进行操作).

To clarify regarding Outlook: Outlook will be installed on the local machine, but it does not have any accounts setup (i.e. all the appropriate libraries will be available, but I need to operate independently from anything setup inside of Outlook).

推荐答案

我很确定如果不使用 Outlook 和 MAPI 配置文件,这将是不可能的.如果您能与您的邮件管理员甜言蜜语,让您在 Exchange 服务器上启用 IMAP,那么您的生活会轻松很多.

I'm pretty sure this is going to be impossible without using Outlook and a MAPI profile. If you can sweet talk your mail admin into enabling IMAP on the Exchange server it would make your life a lot easier.

这篇关于使用 Python 连接到 Exchange 邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11