我使用python3.6,使用zmail库收取邮件时报错: ERR Server Unavailable. 21,是outlook邮箱,我使用网页版登录这个账号是没有问题的

时间: 2024-04-03 11:31:03 浏览: 10
如果你使用zmail库无法连接到Outlook邮箱服务器,可能是因为Outlook邮箱使用的是OAuth2.0验证方式,而zmail库默认使用的是用户名和密码验证方式。因此,你需要使用OAuth2.0验证方式来连接Outlook邮箱服务器。 你可以使用以下步骤来使用zmail库连接Outlook邮箱服务器: 1. 安装Microsoft的请求库requests-oauthlib: ```python pip install requests requests_oauthlib ``` 2. 使用以下代码来连接Outlook邮箱服务器: ```python import zmail from requests_oauthlib import OAuth2Session # 配置OAuth2.0认证信息 client_id = 'your_client_id' client_secret = 'your_client_secret' refresh_token = 'your_refresh_token' resource = 'https://outlook.office.com' oauth = OAuth2Session(client_id, redirect_uri='http://localhost', scope=['openid', 'profile', 'email'], token={'refresh_token': refresh_token}) # 刷新access_token token = oauth.refresh_token('https://login.microsoftonline.com/common/oauth2/v2.0/token', client_id=client_id, client_secret=client_secret) # 构建IMAP连接字符串 imap_url = 'imap-mail.outlook.com' imap_port = 993 imap_tls = True imap_ssl = False imap_auth = {'type': 'OAuth2', 'token': token['access_token']} imap_conn_params = {'host': imap_url, 'port': imap_port, 'tls': imap_tls, 'ssl': imap_ssl, 'auth': imap_auth} # 连接邮箱服务器 server = zmail.server(*imap_conn_params.values()) # 读取邮件 mails = server.get_mails('inbox') ``` 在上面的代码中,你需要替换client_id、client_secret和refresh_token为你Outlook邮箱的客户端ID、客户端密钥和刷新令牌。你可以使用Microsoft的应用注册门户来注册你的应用并获取客户端ID和客户端密钥。你可以使用Microsoft的授权页面来获取刷新令牌。 如果你仍然无法连接到Outlook邮箱服务器,请提供更多的细节信息,方便我更好地帮助你解决问题。

相关推荐

请检查 以下错误W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/Screenshots/Screenshot_20230622_152002.jpg: open failed: EACCES (Permission denied) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:575) W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:160) W/System.err: at okio.Okio__JvmOkioKt.source(JvmOkio.kt:178) W/System.err: at okio.Okio.source(Unknown Source:1) W/System.err: at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167) W/System.err: at okhttp3.MultipartBody.writeOrCountBytes(MultipartBody.kt:157) W/System.err: at okhttp3.MultipartBody.writeTo(MultipartBody.kt:93) W/System.err: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) W/System.err: at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) W/System.err: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err: at java.lang.Thread.run(Thread.java:930) W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied) W/System.err: at libcore.io.Linux.open(Native Method) W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:567) W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:273) W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:567) W/System.err: at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8807) W/System.err: at libcore.io.IoBridge.open(IoBridge.java:561) W/System.err: ... 21 more

最新推荐

recommend-type

解决vue net :ERR_CONNECTION_REFUSED报错问题

主要介绍了解决vue net :ERR_CONNECTION_REFUSED报错问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

Android 出现:java.lang.NoClassDefFoundError...错误解决办法

主要介绍了Android 出现:Android出现:java.lang.NoClassDefFoundError: android/os/PersistableBundle错误解决办法的相关资料,需要的朋友可以参考下
recommend-type

java.net.SocketException: Connection reset 解决方法

最近纠结致死的一个java报错java.net.SocketException: Connection reset 终于得到解决
recommend-type

java.net.ConnectException: Connection refused问题解决办法

主要介绍了java.net.ConnectException: Connection refused问题解决办法的相关资料,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

解释minorization-maximization (MM) algorithm,并给出matlab代码编写的例子

Minorization-maximization (MM) algorithm是一种常用的优化算法,用于求解非凸问题或含有约束的优化问题。该算法的基本思想是通过构造一个凸下界函数来逼近原问题,然后通过求解凸下界函数的最优解来逼近原问题的最优解。具体步骤如下: 1. 初始化参数 $\theta_0$,设 $k=0$; 2. 构造一个凸下界函数 $Q(\theta|\theta_k)$,使其满足 $Q(\theta_k|\theta_k)=f(\theta_k)$; 3. 求解 $Q(\theta|\theta_k)$ 的最优值 $\theta_{k+1}=\arg\min_\theta Q(
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依