为 OWA for Devices 配置推送通知代理

适用于:Exchange Server 2013

通过启用 OWA for Devices (OWA for iPhone 和 OWA for iPad) Microsoft Exchange 2013 本地部署,用户可接收其 OWA for iPhone 和 OWA for iPad 上的Outlook Web App图标上的更新,指示用户收件箱中未看到的消息数。 如果未配置和启用推送通知,那么在不启动应用的情况下,具有 适用于设备的 OWA 的用户将无从知晓收件箱中存在未查看的邮件。 当收到新邮件时,用户设备上的 适用于设备的 OWA 徽章将会更新,看上去和以下徽章一样。

OWA for Devices 徽章。

如何启用推送通知?

若要启用推送通知,本地 Exchange 2013 服务器必须连接到 Microsoft 365 或Office 365推送通知服务,才能将推送通知发送到 iPhone 和 iPad。 Exchange 2013 本地服务器通过 Microsoft 365 或Office 365通知服务路由其更新通知,无需向第三方推送通知服务注册开发人员帐户。 下图显示了 iPhone 和 iPad 用户如何获取有关未查看邮件的徽章更新的流程。

推送通知的过程。

若要启用推送通知,管理员必须执行以下操作:

  1. 在 Microsoft 365 或 Office 365 中注册组织。

  2. 将所有本地服务器更新到 Exchange Server 2013 累积更新 3 (CU3) 或更高版本。

  3. 将本地 Exchange 2013 设置为 Microsoft 365 或 Office 365 身份验证。

  4. 启用从本地 Exchange Server 2013 推送通知到 Microsoft 365 或 Office 365,并验证推送通知是否正常工作。

在 Microsoft 365 或 Office 365 中注册组织

Microsoft 365 和 Office 365 是基于云的服务,旨在帮助满足组织对可靠安全性、可靠性和用户工作效率的需求。 各种可用的订阅计划包括访问 Office 应用程序以及通过 Internet (云服务) 启用的其他生产力服务,例如 Lync Web 会议和Exchange Online托管企业电子邮件。

许多 Microsoft 365 和Office 365计划还包括最新 Office 应用程序的桌面版本,用户可以跨多台计算机和设备安装这些应用程序。 所有 Microsoft 365 和 Office 365 计划均按订阅、按月或按年付费。 若要了解详细信息或为组织注册Office 365,请参阅什么是 Microsoft 365 商业版?。 有关通过 Microsoft 365 和 Office 365 提供的每项服务的详细信息,请参阅 Microsoft 365 和 Office 365 服务说明

升级到 CU3 或更高版本

Exchange Server 2013 的累积更新 3 (CU3) 解决了自 RTM 后发布的 Exchange Server 2013 软件中存在的问题。 其中包含 CU1 和 CU2 中的所有问题和修复以及自 CU2 发布后的其他修复和更新。 强烈建议所有 Exchange Server 2013 本地客户安装此更新,而且这也是接收推送通知所必需的。 若要了解有关累积更新(包括 CU3)的信息,请参阅 Exchange 2013 更新

将本地 Exchange 2013 设置为 Microsoft 365 或Office 365身份验证

Exchange Server 2013 使用单一的标准化服务器到服务器身份验证方法。 Exchange Server 2013 (和 Lync Server 2013SharePoint 2013) 和 Office 2013 支持 OAuth (Open Authorization) 协议,用于服务器到服务器身份验证和授权。 使用 OAuth 时,许多主要网站使用的标准授权协议、用户凭据和密码不会从一台计算机传递到另一台计算机。 相反,身份验证和授权在 OAuth 安全令牌的基础上进行;这些令牌会授予在特定时间段内对一组特定资源的访问权限。

OAuth 身份验证通常涉及到三个组件:一台授权服务器和两个需要互相进行通信的领域。 授权服务器(也称为安全令牌服务器)向需要通信的两个领域颁发安全令牌;这些令牌会确认来自一个领域的通信是否应受另一个领域信任。 例如,授权服务器可能会颁发令牌来验证某个特定 Lync Server 2013 领域的用户是否能够访问指定的 Exchange 2013 领域;反之亦然。

提示

领域是一个安全容器。

但是,对于本地服务器到服务器身份验证,无需使用第三方令牌服务器。 服务器产品(例如 Lync Server 2013 和 Exchange 2013)都具有内置的令牌服务器,可用于其他支持服务器到服务器身份验证的 Microsoft 服务器(例如 SharePoint Server)进行身份验证。 例如,Lync Server 2013 本身可以颁发和签署安全令牌,然后使用该令牌与 Exchange 2013 进行通信。 在这种情况下,不需要第三方令牌服务器。

若要为 Exchange Server 2013 到 Microsoft 365 或 Office 365 的本地实现配置服务器到服务器身份验证,必须完成两个步骤:

  • 步骤 1 - 将证书分配给本地Exchange Server的内置令牌颁发者:首先,如果之前未创建证书,则本地 Exchange 管理员必须使用以下 Exchange 命令行管理程序脚本来创建证书,并将其分配给本地Exchange Server的内置令牌颁发者。 此过程是一次性过程;创建证书后,该证书应重新用于其他身份验证方案,而不是替换。 请确保将 $tenantDomain 的值更新为域的名称。 为此,请复制并粘贴以下代码。

    注意:将代码复制并粘贴到文本编辑器(如记事本)中,并使用 .ps1 扩展将其保存,可以更轻松地运行 Shell 脚本。

    # Make sure to update the following $tenantDomain with your Microsoft 365 or Office 365 organization domain.
    
    $tenantDomain = "Fabrikam.com"
    
    # Check whether the cert returned from Get-AuthConfig is valid and keysize must be >= 2048
    
    $c = Get-ExchangeCertificate | ?{$_.CertificateDomains -eq $env:USERDNSDOMAIN -and $_.Services -ge "SMTP" -and $_.PublicKeySize -ge 2048 -and $_.FriendlyName -match "OAuth"}
    If ($c.Count -eq 0)
    {
        Write-Host "Creating certificate for oAuth..."
        $ski = [System.Guid]::NewGuid().ToString("N")
        $friendlyName = "Exchange S2S OAuth"
        New-ExchangeCertificate -FriendlyName $friendlyName -DomainName $env:USERDNSDOMAIN -Services Federation -KeySize 2048 -PrivateKeyExportable $true -SubjectKeyIdentifier $ski
        $c = Get-ExchangeCertificate | ?{$_.friendlyname -eq $friendlyName}
    }
    ElseIf ($c.Count -gt 1)
    {
        $c = $c[0]
    }
    
    $a = $c | ?{$_.Thumbprint -eq (get-authconfig).CurrentCertificateThumbprint}
    If ($a.Count -eq 0)
    {
        Set-AuthConfig -CertificateThumbprint $c.Thumbprint
    }
    Write-Host "Configured Certificate Thumbprint is:"(get-authconfig).CurrentCertificateThumbprint
    
    # Export the certificate
    
    Write-Host "Exporting certificate..."
    if((test-path $env:SYSTEMDRIVE\OAuthConfig) -eq $false)
    {
        md $env:SYSTEMDRIVE\OAuthConfig
    }
    cd $env:SYSTEMDRIVE\OAuthConfig
    
    $oAuthCert = (dir Cert:\LocalMachine\My) | where {$_.FriendlyName -match "OAuth"}
    $certType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert
    $certBytes = $oAuthCert.Export($certType)
    $CertFile = "$env:SYSTEMDRIVE\OAuthConfig\OAuthCert.cer"
    [System.IO.File]::WriteAllBytes($CertFile, $certBytes)
    
    # Set AuthServer
    $authServer = Get-AuthServer MicrosoftSts;
    if ($authServer.Length -eq 0)
    {
        Write-Host "Creating AuthServer Config..."
        New-AuthServer MicrosoftSts -AuthMetadataUrl https://accounts.accesscontrol.windows.net/metadata/json/1/?realm=$tenantDomain
    }
    elseif ($authServer.AuthMetadataUrl -ne "https://accounts.accesscontrol.windows.net/metadata/json/1/?realm=$tenantDomain")
    {
        Write-Warning "AuthServer config already exists but the AuthMetdataUrl doesn't match the appropriate value. Updating..."
        Set-AuthServer MicrosoftSts -AuthMetadataUrl https://accounts.accesscontrol.windows.net/metadata/json/1/?realm=$tenantDomain
    }
    else
    {
        Write-Host "AuthServer Config already exists."
    }
    Write-Host "Complete."
    

    结果应类似于以下输出:

配置的证书指纹为:7595DBDEA83DACB5757441D44899BCDB9911253C
正在导出证书...
完成。

注意

在继续之前,需要Windows PowerShell cmdlet 的 Azure Active Directory 模块。 如果尚未安装用于 Windows PowerShell cmdlet 的 Azure Active Directory 模块 (以前称为适用于 Windows PowerShell) 的 Microsoft Online Services 模块,则可以使用 Windows PowerShell 从管理Microsoft Entra ID安装它。

  • 步骤 2 - 将 Microsoft 365 或 Office 365配置为与本地 Exchange 2013 通信:将Exchange Server 2013 通信的 Microsoft 365 或 Office 365 服务器配置为合作伙伴应用程序。 例如,如果 Exchange Server 2013 本地需要与 Microsoft 365 或 Office 365 通信,则需要将本地 Exchange 配置为合作伙伴应用程序。 合作伙伴应用程序是可以与 Exchange 2013 直接交换安全令牌的任何应用程序,而无需通过第三方安全令牌服务器。 本地 Exchange 2013 管理员必须使用以下 Exchange 命令行管理程序脚本将 Exchange 2013 与之通信的 Microsoft 365 或 Office 365 组织配置为合作伙伴应用程序。 在执行期间,系统会提示输入 Microsoft 365 或 Office 365 组织域 (的管理员用户名和密码,例如 administrator@fabrikam.com ,) 。 如果未从上一个脚本创建,请确保将 $CertFile 的值更新为证书的位置。 为此,请复制并粘贴以下代码。

    # Make sure to update the following $CertFile with the path to the cert if not using the previous script.
    
    $CertFile = "$env:SYSTEMDRIVE\OAuthConfig\OAuthCert.cer"
    
    If (Test-Path $CertFile)
    {
        $ServiceName = "00000002-0000-0ff1-ce00-000000000000";
    
        $objFSO = New-Object -ComObject Scripting.FileSystemObject;
        $CertFile = $objFSO.GetAbsolutePathName($CertFile);
    
        $cer = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($CertFile)
        $binCert = $cer.GetRawCertData();
        $credValue = [System.Convert]::ToBase64String($binCert);
    
        Write-Host "Please enter the administrator username and password of the Microsoft 365 or Office 365 organization domain..."
    
        Write-Host "Adding a key to Service Principal..."
    
        $p = Get-MgServicePrincipal -Filter "AppId eq '$ServiceName'"
        $params = @{
          keyCredential = @{
              type = "AsymmetricX509Cert"
              usage = "Verify"
              key = $credValue
              endDateTime = $cer.GetExpirationDateString()
              startDateTime = $cer.GetEffectiveDateString()
          }
        }
    
        Add-MgServicePrincipalKey -ServicePrincipalId $p.Id -BodyParameter $params
    
    }
    Else
    {
        Write-Error "Cannot find certificate."
    }
    

    结果应类似于以下输出:

    请输入 Microsoft 365 或 Office 365 组织域的管理员用户名和密码...
    将密钥添加到服务主体...
    完成。

启用推送通知代理

按照上述步骤成功设置 OAuth 身份验证后,本地管理员必须使用以下脚本启用推送通知代理。 请确保将 $tenantDomain 的值更新为域的名称。 为此,请复制并粘贴以下代码。

$tenantDomain = "Fabrikam.com"
Enable-PushNotificationProxy -Organization:$tenantDomain

预期结果应类似于以下输出:

RunspaceId        : 4f2eb5cc-b696-482f-92bb-5b254cd19d60
DisplayName       : On Premises Proxy app
Enabled           : True
Organization      : fabrikam.com
Uri               : https://outlook.office365.com/PushNotifications
Identity          : OnPrem-Proxy
IsValid           : True
ExchangeVersion   : 0.20 (15.0.0.0)
Name              : OnPrem-Proxy
DistinguishedName : CN=OnPrem-Proxy,CN=Push Notifications Settings,CN=First Organization,CN=Microsoft
                    Exchange,CN=Services,CN=Configuration,DC=Domain,DC=extest,DC=microsoft,DC=com
Guid              : 8b567958-58a4-403c-a8f0-524d7f1e9279
ObjectCategory    : fabrikam.com/Configuration/Schema/ms-Exch-Push-Notifications-App
ObjectClass       : {top, msExchPushNotificationsApp}
WhenChanged       : 8/27/2013 7:23:47 PM
WhenCreated       : 8/14/2013 1:30:27 PM
WhenChangedUTC    : 8/28/2013 2:23:47 AM
WhenCreatedUTC    : 8/14/2013 8:30:27 PM
OrganizationId    :
OriginatingServer : server.fabrikam.com
ObjectState       : Unchanged

验证推送通知是否正常工作

完成上述步骤后,将按以下方法之一测试推送通知:

  • 向用户的邮箱发送测试电子邮件:

    1. 在移动设备上的 OWA for Devices 中设置帐户,以订阅通知。

    2. 返回设备主屏幕,这将使 OWA for Devices 在后台工作。

    3. 从另一台设备(如电脑)将一封电子邮件发送到在移动设备上设置的帐户的收件箱。

    4. 这应该会在几分钟内生成未查看邮件的计数(将在应用图标上指明)。

  • 启用监控。 测试推送通知或调查通知失败原因的另一种方法是,在您的组织中对邮箱服务器启用监控。 本地 Exchange 2013 服务器管理员必须通过以下脚本调用推送通知代理监控。 为此,请复制并粘贴以下代码。

    # Send a push notification to verify connectivity.
    
    $s = Get-ExchangeServer | ?{$_.ServerRole -match "Mailbox"}
    If ($s.Count -gt 1)
    {
        $s = $s[0]
    }
    If ($s.Count -ne 0)
    {
        # Restart the monitoring service to clear the cache from when push was previously disabled.
        Restart-Service MSExchangeHM
    
        # Give the monitoring service enough time to load.
        Start-Sleep -Seconds:120
    
        Invoke-MonitoringProbe PushNotifications.Proxy\PushNotificationsEnterpriseConnectivityProbe -Server:$s.Fqdn | fl ResultType, Error, Exception
    }
    Else
    {
        Write-Error "Cannot find a Mailbox server in the current site."
    }
    

    预期结果应类似于以下输出:

    ResultType: Succeeded
    错误:
    例外: