在 SharePoint Server 中配置网站邮箱

适用于:yes-img-132013 yes-img-162016 yes-img-192019 yes-img-seSubscription Edition no-img-sopSharePoint in Microsoft 365

本文介绍了如何在 SharePoint Server 和 Exchange Server 中配置网站邮箱。 借助网站邮箱功能,SharePoint Server 用户可以在网站上访问团队电子邮件。 网站邮箱还提供指向 Microsoft Outlook 中 SharePoint 文档库的链接,以便用户能够与处理联合项目的其他团队成员共享文件和电子邮件。

开始之前

在开始此操作之前,请查看有关先决条件的以下信息:

  • 网站邮箱需要Exchange Server 2013 或更高版本。

  • 需要从 SharePoint 服务器中卸载任何早期版本的 Exchange Web 服务 (EWS)。

    注意

    您可能需要确定是否安装了早期版本的 EWS。 如果是,请运行下面提到的 Check-SiteMailboxConfig 脚本。

  • 站点邮箱功能要求在场中配置用户配置文件同步。 有关配置用户配置文件同步的信息,请参阅计划用户配置文件和标识管理 SharePoint 服务器中的用户配置文件同步

  • 网站邮箱功能需要在服务器场中配置 App Management Service 应用程序。 有关配置 App Management Service 应用程序的信息,请参阅 New-SPAppManagementServiceApplication

  • 对于部署在支持服务器到服务器身份验证和应用程序身份验证的方案中的 Web 应用程序,需要为默认区域配置安全套接字层 (SSL)。 它是这样一种方案。 作为配置网站邮箱的先决条件,运行 SharePoint Server 的计算机必须已配置 SSL。 有关详细信息,请参阅在 SharePoint 服务器中创建基于声明的 web 应用程序,并按照创建 SSL 网站集和服务器证书的步骤操作。

请注意,可能需要将 Exchange Server SSL 证书从 Exchange Server 导入 SharePoint Server,并将 SharePoint Server 导入到 Exchange Server。 仅当证书不信任 API 终结点 ((例如实验室环境中的自 SSL 证书) )时,才有必要这样做。 将不受信任的 SSL 证书导入新服务器:

  • 打开 Internet Explorer 并导航到 Outlook Web App(如果部署位于 SharePoint Server 中)或者 SSL SharePoint 网站(如果部署位于 Exchange Server 中):https://<ExServerName>/owa 或 https://<SP_FQDN>。

  • 单击“继续浏览网站”接受以信任该证书。

  • 单击 Internet Explorer 中地址栏旁边的“证书错误”信息,然后单击“查看证书”。

  • 选择“安装证书”,然后选择“将所有的证书放入下列存储”。

  • 选中复选框以显示物理存储区。

  • 将证书安装到受信任的根证书颁发机构 > 本地计算机。

  • 为了执行这些过程,您必须是 SharePoint 和 Exchange Server 管理员组的成员,并且有一个具有最终用户邮箱的可操作的 Exchange Server。

  • SharePoint 备份解决方案不会合并 Exchange 网站邮箱。 Exchange 管理员将需要确保及时备份网站邮箱。

  • 从网站邮箱访问 SharePoint 文档库中文件的用户必须在浏览器中将文档库配置为受信任的网站,否则将显示警告,询问用户是否要信任该文件。

在 SharePoint Server 中为 SharePoint 配置网站邮箱

配置网站邮箱的第一步是,在 SharePoint Server 场中每个 Web 服务器和应用程序服务器上安装 Exchange Server Web 服务 API。

在 SharePoint Server 上安装 Exchange Web 服务 API

  1. 从 Microsoft 下载中心下载 EWSManagedAPI.msi,并将它保存到每个 Web 服务器和应用程序服务器上的文件夹中。

  2. 以管理员身份打开一个命令窗口,并导航到保存 EWSManagedAPI.msi 的文件夹。

  3. 运行以下命令:

    msiexec /I EwsManagedApi.msi addlocal="ExchangeWebServicesApi_Feature"
    
  4. 通过从命令行键入以下命令重置 IIS: IISReset.

在 SharePoint Server 上建立 OAuth 信任和服务权限

下一步是复制以下两个脚本。 应将第一个脚本另存为 Set-SiteMailboxConfig.ps1,将第二个另存为 Check-SiteMailboxConfig.ps1。

Set-SiteMailboxConfig.ps1:

# .SYNOPSIS
#
# Set-SiteMailboxConfig helps configure Site Mailboxes for a SharePoint farm
#
# .DESCRIPTION
#
# Establishes trust with an Exchange Server, sets Site Mailbox settings and enables Site Mailboxes for a farm.
#
# .PARAMETER ExchangeSiteMailboxDomain
#
# The FQDN of the Exchange Organization where Site Mailboxes will be created
#
# .PARAMETER ExchangeAutodiscoverDomain
#
# [Optional] The FQDN of an Exchange Autodiscover Virtual Directory
#
# .PARAMETER WebApplicationUrl
#
# [Optional] The URL of a specific web application to configure. If not specified all Web Applications will be configured
#
# .PARAMETER Force
#
# [Optional] Indicate that the script should ignore any configuration issues and enable Site Mailboxes anyway
#
Param
(
   [Parameter(Mandatory=$true)]
   [ValidateNotNullOrEmpty()]   
   [string]$ExchangeSiteMailboxDomain,
   [Parameter(Mandatory=$false)]
   [ValidateNotNullOrEmpty()]   
   [string]$ExchangeAutodiscoverDomain,
   [Parameter(Mandatory=$false)]
   [ValidateNotNullOrEmpty()]   
   [string]$WebApplicationUrl,
   [Parameter(Mandatory=$false)]
   [switch]$Force
)
$script:currentDirectory = Split-Path $MyInvocation.MyCommand.Path
if($WebApplicationUrl -ne $NULL -and $WebApplicationUrl -ne "")
{
    $webapps = Get-SPWebApplication $WebApplicationUrl
}
else
{
    $webapps = Get-SPWebApplication
}
if($webapps -eq $NULL)
{
    if($WebApplicationUrl -ne $NULL)
    {
        Write-Warning "No Web Application Found at $($WebApplicationUrl). Please create a web application and re-run Set-SiteMailboxConfig"
    }
    else
    {
        Write-Warning "No Web Applications Found. Please create a web application and re-run Set-SiteMailboxConfig"
    }
    
    return
}
$rootWeb = $NULL
foreach($webapp in $webapps)
{
    if($rootWeb -eq $NULL)
    {
        $rootWeb = Get-SPWeb $webApp.Url -EA SilentlyContinue
    }
}
if($rootWeb -eq $NULL)
{
    Write-Warning "Unable to find a root site collection. Please create a root site collection on a web application and re-run Set-SiteMailboxConfig"
    return
}
$exchangeServer = $ExchangeAutodiscoverDomain
if($exchangeServer -eq $NULL -or $exchangeServer -eq "")
{
    $exchangeServer = "autodiscover.$($ExchangeSiteMailboxDomain)"
}
Write-Host "Establishing Trust with Exchange Server: $($exchangeServer)"
$metadataEndpoint = "https://$($exchangeServer)/autodiscover/metadata/json/1"
$exchange = Get-SPTrustedSecurityTokenIssuer | Where-Object { $_.MetadataEndpoint -eq $metadataEndpoint }
if($exchange -eq $NULL)  
{
    $exchange = New-SPTrustedSecurityTokenIssuer -Name $exchangeServer -MetadataEndPoint $metadataEndpoint
}
if($exchange -eq $NULL)
{
    Write-Warning "Unable to establish trust with Exchange Server $($exchangeServer). Ensure that $($metadataEndpoint) is accessible."
    if($ExchangeAutodiscoverDomain -eq $NULL -or $ExchangeAutodiscoverDomain -eq "")
    {
        Write-Warning "If $($metadataEndpoint) doesn't exist, you may specify an alternate FQDN using ExchangeAutodiscoverDomain."
    }
    return
}
Write-Host "Granting Permissions to Exchange Server: $($exchangeServer)"
$appPrincipal = Get-SPAppPrincipal -Site $rootWeb.Url -NameIdentifier $exchange.NameId
Set-SPAppPrincipalPermission -AppPrincipal $appPrincipal -Site $rootWeb -Scope SiteSubscription -Right FullControl -EnableAppOnlyPolicy
Write-Host
Write-Host
Write-Host "Verifying Site Mailbox Configuration"
$warnings = & $script:currentDirectory\Check-SiteMailboxConfig.ps1 -ReturnWarningState
if($warnings -and -not $Force)
{
    Write-Warning "Pre-requisites not satisfied. Stopping Set-SiteMailboxConfig. Use -Force to override"
    return
}
elseif($warnings)
{
    Write-Warning "Pre-requisites not satisfied. -Force used to override"
}
foreach($webapp in $webapps)
{
    Write-Host "Configuring Web Application: $($webapp.Url)"
    Write-Host "Setting Exchange Site Mailbox Domain to $($ExchangeSiteMailboxDomain)"
    $webapp.Properties["ExchangeTeamMailboxDomain"] = $ExchangeSiteMailboxDomain
        
    if($ExchangeAutodiscoverDomain -ne $NULL -and $ExchangeAutodiscoverDomain -ne "")
    {
        Write-Host "Setting Exchange Autodiscover Domain to $($ExchangeAutodiscoverDomain)"
        $webapp.Properties["ExchangeAutodiscoverDomain"] = $ExchangeAutodiscoverDomain;
    }
    $webapp.Update()
}
$feature = Get-SPFeature CollaborationMailboxFarm -Farm -ErrorAction Ignore
if($feature -eq $NULL)
{
    Write-Host "Enabling Site Mailboxes for Farm"
    Enable-SPFeature CollaborationMailboxFarm
}
else
{
    Write-Host "Site Mailboxes already enabled for Farm"
}

Check-SiteMailboxConfig.ps1:

Param
(
   [Parameter(Mandatory=$false)]
   [ValidateNotNullOrEmpty()]   
   [switch]$ReturnWarningState
)
Add-PSSnapin Microsoft.SharePoint.Powershell
$anyWarnings = $false
Write-Host "Step 1: Checking for Exchange Web Services"
try
{
    $assm = [System.Reflection.Assembly]::Load("Microsoft.Exchange.WebServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
    if($assm.GlobalAssemblyCache)
    {
        Write-Host -Foreground Green "Found Exchange Web Services in Global Assembly Cache"
        Write-Host "Exchange Web Services Version: $([System.Diagnostics.FileVersionInfo]::GetVersionInfo($assm.Location).FileVersion)"
    }
    else
    {
        Write-Warning "Unable to find Exchange Web Services in Global Assembly Cache"
        $anyWarnings = $true
    }
}
catch
{
    Write-Warning "Unable to find Exchange Web Services in Global Assembly Cache"
    $anyWarnings = $true
}
Write-Host
Write-Host
Write-Host "Step 2: Checking for https web application"
$webapps = Get-SPWebApplication -EA SilentlyContinue
$rootWeb = $NULL
if($webapps -ne $NULL)
{
    $sslWebAppExists = $false
    foreach($webapp in $webapps)
    {
        if($rootWeb -eq $NULL)
        {
            $rootWeb = Get-SPWeb $webApp.Url -EA SilentlyContinue
        }
        if(-not $webapp.Url.StartsWith("https://"))
        {
            Write-Warning "Web Application at $($webapp.Url) does not use HTTPS. Site Mailboxes will not work on this Web Application."
        }
        else
        {
            $sslWebAppExists = $true
            Write-Host -Foreground Green "Found Web Application at $($webapp.Url) that uses HTTPS"
        }
    }
    if(-not $sslWebAppExists)
    {
        Write-Warning "At least one Web Application must be configured for HTTPS in the default zone."
        $anyWarnings = $true
    }
}
else
{
    Write-Warning "No Web Applications Found. Please create a web application and re-run Check-SiteMailboxConfig"
    $anyWarnings = $true
    if($ReturnWarningState)
    {
        return $anyWarnings
    }
    return;
}
if($rootWeb -eq $NULL)
{
    Write-Warning "Unable to find any Sites. Please create a root site collection on a web application and re-run Check-SiteMailboxConfig"
    $anyWarnings = $true
    if($ReturnWarningState)
    {
        return $anyWarnings
    }
    return;
}
# Get App Permissions Management Objects
$appPrincipalManager = [Microsoft.SharePoint.SPAppPrincipalManager]::GetManager($rootWeb)
$appPrincipalPermissionsManager = New-Object -TypeName Microsoft.SharePoint.SPAppPrincipalPermissionsManager -ArgumentList $rootWeb        
Write-Host
Write-Host
Write-Host "Step 3: Checking for trusted Exchange Servers"
$trustedIssuers = Get-SPTrustedSecurityTokenIssuer
$trustedIssuerHosts = @()
if($trustedIssuers -ne $NULL)
{
    $foundTrustedIssuer = $false
    foreach($trustedIssuer in $trustedIssuers)
    {
        if($trustedIssuer.RegisteredIssuerName.StartsWith("00000002-0000-0ff1-ce00-000000000000@"))
        {
            if($trustedIssuer.IsSelfIssuer)
            {
                $foundTrustedIssuer = $true
                $uri = New-Object -TypeName System.Uri -ArgumentList $trustedIssuer.MetadataEndPoint
                
                Write-Host -Foreground Green "Found trusted Exchange Server at $($uri.Host)"
                $appPrincipalName = [Microsoft.SharePoint.SPAppPrincipalName]::CreateFromNameIdentifier($trustedIssuer.RegisteredIssuerName)
                $appPrincipal = $appPrincipalManager.LookupAppPrincipal([Microsoft.SharePoint.SPAppPrincipalIdentityProvider]::External, $appPrincipalName);
                
                if($appPrincipal -ne $NULL)
                {
                    $isValidAppPrincipal = $true;
                    if($appPrincipalPermissionsManager.GetAppPrincipalSiteSubscriptionContentPermission($appPrincipal) -eq [Microsoft.SharePoint.SPAppPrincipalPermissionKind]::FullControl)
                    {
                        Write-Host -Foreground Green "Exchange Server at $($uri.Host) has Full Control permissions"
                        
                    }
                    else
                    {
                        Write-Warning "Exchange Server at $($uri.Host) does not have Full Control permissions"
                        $isValidAppPrincipal = $false;
                        $anyWarnings = $true
                    }
                    if($appPrincipalPermissionsManager.IsAppOnlyPolicyAllowed($appPrincipal))
                    {
                        Write-Host -Foreground Green "Exchange Server at $($uri.Host) has App Only Permissions"
                    }
                    else
                    {
                        Write-Warning "Exchange Server at $($uri.Host) does not have App Only Permissions"
                        $isValidAppPrincipal = $false;
                        $anyWarnings = $true
                    }
                    
                    if($isValidAppPrincipal)
                    {
                        $trustedIssuerHosts += $uri.Host
                    }
                }
                else
                {
                    Write-Warning "Unable to get App Principal for $($uri.Host). Unable to check permissions for this Exchange Server"
                    $anyWarnings = $true
                }
            }
            else
            {
                Write-Warning "Found trusted Exchange Server at $($uri.Host) but it is not a Self Issuer"
                $anyWarnings = $true
            }
        }
    }
    if(-not $foundTrustedIssuer)
    {
        Write-Warning "Unable to find any trusted Exchange Servers"
        $anyWarnings = $true
    }
}
else
{
    Write-Warning "Unable to find any trusted Exchange Servers"
    $anyWarnings = $true
}
Write-Host
Write-Host
Write-Host "Step 4: Report current Site Mailbox Configuration"
if($webapps -ne $NULL)
{
    foreach($webapp in $webapps)
    {
        Write-Host
        Write-Host "Web Application Site Mailbox Configuration: $($webapp.Url)"
        Write-Host "Exchange Site Mailbox Domain: $($webapp.Properties["ExchangeTeamMailboxDomain"])"
        
        if($webapp.Properties["ExchangeAutodiscoverDomain"] -ne $NULL)
        {
            Write-Host "Exchange Autodiscover Domain: $($webapp.Properties["ExchangeAutodiscoverDomain"])"
        }
    }
}
Write-Host
Write-Host "Trusted Exchange Services: $([String]::Join(", ", $trustedIssuerHosts))"
$feature = Get-SPFeature CollaborationMailboxFarm -Farm -ErrorAction Ignore
if($feature -eq $NULL)
{
    Write-Host -ForegroundColor Red "Site Mailboxes are NOT enabled for Farm"
}
else
{
    Write-Host -ForegroundColor Green "Site Mailboxes are enabled for Farm"
}
if($ReturnWarningState)
{
    return $anyWarnings
}

Save the two .ps1 files to the same folder on a SharePoint Server Front-end or Application server, as one script calls the other during execution. In a Microsoft PowerShell window (right-click the PowerShell icon and choose Run As Administrator to open), navigate to the folder containing the .ps1 files and run the Set-SiteMailboxConfig.ps1 script. This allows users to do the following:

  • 检索和安装 Exchange 元数据以便为 Exchange 服务主体提供对 SharePoint 网站订阅的完全控制权

  • 在 SharePoint 环境中启用网站邮箱功能

  • (可选)设置 Exchange 网站邮箱目标域(如果尚未为域 DNS 配置自动发现的话)

Check-SiteMailboxConfig.ps1 是作为 Set-SiteMailboxConfig 脚本的一部分调用的,它将确认配置是否成功(还可以单独运行该脚本)。

格式应如下所示:

   .\Set-SiteMailboxConfig.ps1 -ExchangeSiteMailboxDomain \<Domain\> -ExchangeAutodiscoverDomain [Exchange Server] -WebApplicationUrl [URL]

其中,<Domain> 将为您的 Exchange Server 所在的域的 FQDN,<Exchange Server> 为要连接到的 Exchange Server。 这是必需参数。

可选参数是 [Exchange Server] 和 [URL]。前者是要连接到的 Exchange Server(如果未启用或未正确配置自动发现,则需要此参数),后者是可能要配置的特定 URL(通常用于包含 SSL 和非 SSL Web 应用程序的环境)。

示例:

   .\Set-SiteMailboxConfig.ps1 -ExchangeSiteMailboxDomain tailspintoys.com -ExchangeAutodiscoverDomain exchange1.tailspintoys.com -WebApplicationUrl https://tailspintoys.com

如果在运行脚本时遇到错误,请参阅本文中的“疑难解答”部分,以获得相应指导。

为 Exchange Server 配置网站邮箱

最后一步是,在 Exchange 服务器上建立 OAuth 信任和服务权限。

在 Exchange 上建立 OAuth 信任和服务权限

  1. 在 Exchange Server 实例中以管理员身份打开 Exchange Management PowerShell 窗口并转至"C:\Program Files\Microsoft\Exchange Server\V15\Scripts"目录。

  2. 运行以下命令:

    .\Configure-EnterprisePartnerApplication.ps1 -ApplicationType Sharepoint -AuthMetadataUrl https://<SP_FQDN>/_layouts/15/metadata/json/1
    

    其中 <SP_FQDN> 是您要配置的 SharePoint SSL 根网站集的 URL。

故障排除

请如果您遇到问题,查看下表。

运行配置检查表脚本时的错误代码参考表

错误代码 错误 注释
0
NoError
查看先决条件。
1
ExchangeClientNotAvailable
在 SharePoint WFE 上找不到 EWS 客户端。 运行 Check 脚本并确保 GAC 中的条目正确无误;您可能需要重新安装 EWS 客户端。
2
UnsupportedVersion
EWS 客户端版本与 SharePoint 不兼容。 运行 Check 脚本以确保版本满足最低要求。 或者,Exchange Server 可能是 2010 或较低版本。
3
InvalidUser
TeamMailboxDomain 参数不是有效的 FQDN 或 SMTP 地址。
4
UnauthorizedUser
该脚本从 Exchange Server 收到 401 消息,请查看 Exchange 安装步骤。
5
ServerBusy
Exchange 在自动发现期间超时。 它应该是间歇性的,请重试,但如果它持续存在,请与 Exchange 管理员跟进。
6
URLNotAvailable
自动发现未能返回 ECP/OWA 的 URL,这通常意味着 EWS 客户端版本与 SharePoint 不兼容。 它还可能意味着未在 Exchange 上启用网站邮箱,这将需要咨询 Exchange 管理员。
7
OAuthNotSupported
代表 SharePoint 生成 OAuth 令牌不成功。 这通常是由要在 SharePoint Web 应用程序中禁用的基于声明的身份验证引起的。
8
OAuthException
在 SharePoint 和 Exchange 之间 OAuth 握手期间发生错误。 这通常是由服务器到服务器的配置问题导致的,例如两端的领域值不匹配、Exchange 或 SharePoint 的证书问题等。查看证书并尝试建立或重新建立信任。
9
InvalidAutodiscoverDomain
自动发现域属性未设置为有效的 FQDN。
10
UnknownError
发生未知错误情况。 运行检查脚本并确认有效的受信任的 SharePoint 实例可用,查看先决条件,确认自动发现是否已使用 Exchange 管理员正确设置。
101
OAuthNotSupportedOverHttp
如果引发此错误,表明 Web 应用程序的默认区域未设置为 SSL,并且 AllowOauthoverHttp 设置为 False。 请按照先决条件中所述运行 Check 脚本以确保要承载网站邮箱的所有 Web 应用程序已在默认区域中设置了 SSL。
102
AssociatedOwnersGroupNull
已删除网站的默认 Owners 组和/或 Members 组。 这两个默认组都需要存在于用户安装站点邮箱的任何站点上。 网站管理员应能够指示网站所有者重新创建这些必需的组。
103
ExchangeTeamMailboxDomainNotSet
尚未设置 ExchangeTeamMailboxDomain 属性。
104
ExchangeAppPrincipalNotFound
未发现要信任的 Exchange 应用程序主体。 这通常意味着遗漏了 New-SPTrustedSecureTokenService 步骤。 请运行 Check 脚本并确保输出的应用程序主体 URL 正确无误。
105
ExchangeAppPrincipalMissingPermissions
要连接到的 Exchange 应用程序主体不具有 SharePoint 场的适当权限。 请运行 Check 脚本并确保 Exchange 应用程序主体具有服务器场的必需权限。

另请参阅

概念

Plan email integration for a SharePoint Server farm

Configure email integration for a SharePoint Server farm

其他资源

网站邮箱

协作