- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如你们许多人所知,从 2022 年 1 月 10 日起,Microsoft 将弃用 Exchange online 的基本身份验证(登录名和密码)。您可以在这里阅读全文:
我目前正在使用 PHPMailer 从应用程序通过 SMTP 发送电子邮件。
当前代码的工作示例:
<?php
include "vendor/autoload.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.office365.com";
$mail->Port = "587";
$mail->SMTPAuth = true;
$mail->Username = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="513c280e343c30383d113c287c323e3c21303f287f323e3c" rel="noreferrer noopener nofollow">[email protected]</a>";
$mail->Password = "my_password";
$mail->SMTPSecure = "tls";
$mail->From = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5246605a525e56537f5246125c50524f5e5146115c5052" rel="noreferrer noopener nofollow">[email protected]</a>";
$mail->FromName = "my_name";
$mail->AddAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="701d092f151d11191c301d095d131f1d00111e095e131f1d" rel="noreferrer noopener nofollow">[email protected]</a>");
$mail->IsHTML(true);
$mail->Subject = "This is a test subject";
$mail->Body = "Hello, how are you?";
$mail->Send();
?>
我想从基本身份验证转移到 OAuth 2.0。在阅读了大量文档、在网上搜索了 3 天、尝试了又尝试之后,我无法让它工作。
我的新代码示例:
<?php
include "vendor/autoload.php";
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = "smtp.office365.com";
$mail->SMTPAuth = true;
$mail->AuthType = "XOAUTH2";
$mail->SMTPDebug = SMTP::DEBUG_LOWLEVEL;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$username = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92ffebcdf7fff3fbfed2ffebbff1fdffe2f3fcebbcf1fdff" rel="noreferrer noopener nofollow">[email protected]</a>";
$clientId = "client_id_from_azure_app_registration";
$clientSecret = "client_secret_from_azure_app_registration";
$redirectURI = "my_redirect_uri";
$Token = "my_token";
$mail->refresh_token = $Token;
$provider = new Stevenmaguire\OAuth2\Client\Provider\Microsoft(
[
"clientId" => $clientId,
"clientSecret" => $clientSecret,
"redirectUri" => $redirectURI
]
);
$provider->urlAPI = "https://outlook.office365.com/.default";
$provider->scope = "Mail.Send";
$mail->setOAuth(
new OAuth(
[
"provider" => $provider,
"clientId" => $clientId,
"clientSecret" => $clientSecret,
"refreshToken" => $Token,
"userName" =>$username
]
)
);
$mail->From = $username;
$mail->AddAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="137e6a4c767e727a7f537e6a3e707c7e63727d6a3d707c7e" rel="noreferrer noopener nofollow">[email protected]</a>");
$mail->IsHTML(true);
$mail->Subject = "This is a test subject";
$mail->Body = "Hello, how are you?";
$mail->Send();
?>
我通过 Postman 生成访问 token 并在上面的代码中使用此 token :
应用程序在 Microsoft Azure 中配置为具有所需的权限:
这是我得到的输出:
2022-09-27 13:51:38 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2022-09-27 13:51:38 Connection: opened
2022-09-27 13:51:38 SMTP INBOUND: "220 AS4P191CA0011.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 27 Sep 2022 13:51:37 +0000"
2022-09-27 13:51:38 SERVER -> CLIENT: 220 AS4P191CA0011.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 27 Sep 2022 13:51:37 +0000
2022-09-27 13:51:38 CLIENT -> SERVER: EHLO
2022-09-27 13:51:38 SMTP INBOUND: "250-AS4P191CA0011.outlook.office365.com Hello [2a02:4780:8:2::25]"
2022-09-27 13:51:38 SMTP INBOUND: "250-SIZE 157286400"
2022-09-27 13:51:38 SMTP INBOUND: "250-PIPELINING"
2022-09-27 13:51:38 SMTP INBOUND: "250-DSN"
2022-09-27 13:51:38 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2022-09-27 13:51:38 SMTP INBOUND: "250-STARTTLS"
2022-09-27 13:51:38 SMTP INBOUND: "250-8BITMIME"
2022-09-27 13:51:38 SMTP INBOUND: "250-BINARYMIME"
2022-09-27 13:51:38 SMTP INBOUND: "250-CHUNKING"
2022-09-27 13:51:38 SMTP INBOUND: "250 SMTPUTF8"
2022-09-27 13:51:38 SERVER -> CLIENT: 250-AS4P191CA0011.outlook.office365.com Hello [2a02:4780:8:2::25]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-09-27 13:51:38 CLIENT -> SERVER: STARTTLS
2022-09-27 13:51:38 SMTP INBOUND: "220 2.0.0 SMTP server ready"
2022-09-27 13:51:38 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2022-09-27 13:51:38 CLIENT -> SERVER: EHLO
2022-09-27 13:51:38 SMTP INBOUND: "250-AS4P191CA0011.outlook.office365.com Hello [2a02:4780:8:2::25]"
2022-09-27 13:51:38 SMTP INBOUND: "250-SIZE 157286400"
2022-09-27 13:51:38 SMTP INBOUND: "250-PIPELINING"
2022-09-27 13:51:38 SMTP INBOUND: "250-DSN"
2022-09-27 13:51:38 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2022-09-27 13:51:38 SMTP INBOUND: "250-AUTH LOGIN XOAUTH2"
2022-09-27 13:51:38 SMTP INBOUND: "250-8BITMIME"
2022-09-27 13:51:38 SMTP INBOUND: "250-BINARYMIME"
2022-09-27 13:51:38 SMTP INBOUND: "250-CHUNKING"
2022-09-27 13:51:38 SMTP INBOUND: "250 SMTPUTF8"
2022-09-27 13:51:38 SERVER -> CLIENT: 250-AS4P191CA0011.outlook.office365.com Hello [2a02:4780:8:2::25]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-09-27 13:51:38 Auth method requested: XOAUTH2
2022-09-27 13:51:38 Auth methods available on the server: LOGIN,XOAUTH2
Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException: Bad Request in /home/u760208683/vendor/stevenmaguire/oauth2-microsoft/src/Provider/Microsoft.php:79 Stack trace: #0 /home/u760208683/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(628): Stevenmaguire\OAuth2\Client\Provider\Microsoft->checkResponse(Object(GuzzleHttp\Psr7\Response), Array) #1 /home/u760208683/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(537): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request)) #2 /home/u760208683/vendor/phpmailer/phpmailer/src/OAuth.php(115): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\RefreshToken), Array) #3 /home/u760208683/vendor/phpmailer/phpmailer/src/OAuth.php(128): PHPMailer\PHPMailer\OAuth->getToken() #4 /home/u760208683/vendor/phpmailer/phpmailer/src/SMTP.php(598): PHPMailer\PHPMailer\OAuth->getOauth64() #5 /home/u760208683/vendor/phpmailer/phpmailer/src/PHPMailer in /home/u760208683/vendor/stevenmaguire/oauth2-microsoft/src/Provider/Microsoft.php on line 79
有人能指出我正确的方向吗?
非常感谢!
亲切的问候,洛朗
最佳答案
Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException:
此错误是由于您提供的是 access_token 来发送邮件,而不是刷新_token。
首先,添加范围offline_access以在授权网址中获取refresh_token并将其保存在应用程序中的某个位置(过期时间为24小时或90天,具体取决于应用程序类型)获得刷新 token 后,您可以使用相同的 token 发送任意数量的邮件。
您可以通过在网址中提供另一个未过期的刷新 token 并将 grant_type 更改为刷新 token 并添加 key 刷新 token 来获取新 token 。
关于php - 如何在 PHPMailer for Exchange Online 中实现 Oauth 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73868867/
任务是编写代码,将敏感度标签应用于 SharePoint Online 文档库中的文档,而无需下载文件。 到目前为止,我已经探索了以下 API: SharePoint REST API v1 :可用于
期望的行为 将托管在 SharePoint Online 上的 Excel 文档嵌入到 HTML 页面中。 实际行为 嵌入加载,但是没有水平滚动条。 获取视口(viewport)右侧数据的唯一方法是单
我想在数据中心选择一个事件分区。通常我会使用以下语句: INVANTIVE> use 1552839 2> Exclamation itgendhb077: Error in Invantive Da
我正在使用 Azure Functions,特别是 PowerShell 脚本函数。我想知道如何使用连接到 SharePoint Online 的脚本。 要针对 SharePoint Online 运
我正在尝试使用 API 按姓名查询客户。具有非 ASCII 字符的名称(例如 민준 或 Włodarski)会导致查询失败。这是一个示例查询: SELECT * FROM Customer WHERE
我已经将一个SharePoint列表从2019年迁移到365年。该列表具有NINTEX形式,而该NINTEX形式具有较少的JavaScript文件。在SP Online中,NWF$().SPServi
我正在尝试在内存中生成 PDF 以将其发送到 WS。此 PDF 应在内存 (Stream) 和 Microsoft CRM“云”中的插件代码中创建。这可能吗? 在插件中(已经编码和部署)我有这行,第
当我使用 Invantive Data Hub 从多个 Exact Online 公司下载数据时,我得到了重复的行,而我希望每个公司只有一行。 我使用以下查询: select gla.code ,
我们刚刚上线 https://ecotaksen.be 。 Exact 上的查询和更新运行良好,但安装生产许可证后出现错误 itgenobr001:找不到客户端。。 我的数据容器规范是: 使用具有相
我在 Dynamics CRM Online 2015 中创建了一个插件,用于在 SharePoint Online 文档库中创建文件夹。该插件工作正常。但是,我想在 CRM 中的帐户名称更改时重命名
我正在关注 this blog在 SPFX 部分实现 fluentUI,但在执行“Gulp Build”时出现以下错误: Error - [tsc] node_modules/@fluentui/re
我能够在桌面 .Net 项目中通过 MSAL 检索和使用访问 token 。我可以成功检索 token ,并且它们在我的 Graph 调用中有效。 但是,尝试将访问 token 与 SharePoin
为了遵守法规,我尝试从我的一些部门下载采购发票文件(PDF 文件),将它们保存在磁盘上以供存档。 我使用 Invantive 查询工具来执行此操作。我想知道使用哪个表以及如何仅针对采购发票文档导出这些
我正在开发一个基于 Spring-MVC 的 Web 应用程序,该应用程序使用 Cometd 进行聊天。为了实时管理哪些用户在线,我们在用户在线时发送通知。因此,当窗口关闭时,不会出现通知,并且 30
我在 Visual Studio Online 上使用 GIT 进行源代码管理。我想将一个项目从我的个人 VSO 账户转移到我的企业 VSO 账户。例如。从 account1.visualstudio
当我关闭 Word Online 中的对话框时,我在控制台中收到以下消息: Unknown conversation Id. 我不是得到一个可以处理的代码,而是得到...... (macOS/Chro
短版:如何加载 PowerApps 中托管元数据字段的所有可用选项? 长版: 我有一个正常工作的 PowerApps 应用程序,但用户希望能够在离线时添加数据,并在再次在线时同步回来。官方 Power
我是 QuickBooks 的新手,我所有的搜索都导致了相互矛盾的答案。我真的需要知道这一点才能继续前进。 我们有一个本地应用程序(如果重要的话,旧版 MFC 应用程序)。我们的一些客户使用 Quic
这是我的代码,我尝试使用 countOnline 函数计算我们有多少在线用户。 我遇到错误“无法读取未定义的‘在线’属性”; function countOnline(usersObj) { le
如果我们有一个巨大的事实表并想要添加一个新维度,我们可以这样做: BEGIN TRANSACTION ALTER TABLE [GiantFactTable] ADD NewDimValueId IN
我是一名优秀的程序员,十分优秀!