outlook - 使用 EWS API 发送电子邮件方法获取 401 未经授权
问题描述
我对 EWS API 很陌生。现在我在使用 EWS 示例发送电子邮件时遇到问题。仍然收到错误:
401 未经授权。
这是我的示例代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user1@contoso.com", "password");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("user1@contoso.com", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user1@contoso.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API");
email.Send();
email.Send() 函数中的错误。对此有什么帮助吗?相关链接:https ://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications
我搜索了所有链接,但没有正确答案。
解决方案
在黑暗中拍摄,但很容易尝试:几年前,我遇到了无法解释的 401,发现一些网络帖子提到向服务对象添加一个空的 cookie 容器,即:
service.CookieContainer = new CookieContainer();
当时它似乎起到了作用,但不确定它是否仍然是一件事。
推荐阅读
- java - Kotlin 序列:过滤器 + 先查找 + 映射
- python - 有没有办法通过 Anaconda 或 Python 3 解释 GLPK 或 lp 文件?
- c# - 用户棱镜库 使用 WPF,DataTrigger 无法在 ItemContainerStyle 中触发。获取 ViewModel 实例的任何建议
- node.js - Schema 关系:传入的参数必须是 12 个字节的单个字符串或 24 个十六进制字符的字符串
- bash - 使用 for 循环时保持格式
- python - Selenium 点击按钮 Python
- javascript - 在“onclick”事件上调用的函数是否等待函数结束?
- gradle - 如何在 Github Actions 中将 Checkstyle 结果报告为拉取请求注释?
- php - 如何不修改 php-cs-fixer 的某些注释?
- ios - 我们是否应该避免手动清除 iOS tmp 和 Caches 文件夹?