You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Graph API按ID转发Office365单封邮件(PowerShell场景)

用Microsoft Graph PowerShell转发指定ID邮件的方法

Microsoft Graph PowerShell模块没有直接命名为Forward-MgUserMessage的cmdlet,但可以通过Invoke-MgForwardUserMessage命令实现转发,这是对应Graph API转发邮件端点的封装。

核心步骤与代码示例

  1. 准备必要参数:确认目标用户邮箱$email、待转发邮件ID$messageId、接收转发的邮箱(你的邮箱)$myEmail。
  2. 构造收件人对象:按Graph API要求的格式定义收件人。
  3. 执行转发命令:
# 定义收件人
$forwardRecipients = @(
    @{
        EmailAddress = @{
            Address = $myEmail
        }
    }
)

# 执行转发,默认会包含原邮件的附件
Invoke-MgForwardUserMessage -UserId $email -MessageId $messageId -BodyParameter @{
    Comment = "此邮件为转发排查附件问题使用"
    ToRecipients = $forwardRecipients
}

补充说明

  • 如果是从Get-MgUserMessage的结果中筛选指定ID的邮件,可以直接复用邮件对象的Id属性:
    $targetMessageId = "你的目标邮件ID"
    $messages = Get-MgUserMessage -UserId $email -Filter "IsRead eq false"
    $targetMsg = $messages | Where-Object { $_.Id -eq $targetMessageId }
    
    if ($targetMsg) {
        Invoke-MgForwardUserMessage -UserId $email -MessageId $targetMsg.Id -BodyParameter @{
            Comment = "转发排查附件"
            ToRecipients = @(@{EmailAddress = @{Address = $myEmail}})
        }
    }
    
  • 权限检查:确保连接Graph时已申请Mail.Send权限,否则会报错。连接命令示例:
    Connect-MgGraph -Scopes "Mail.Read","Mail.Send"
    
  • 转发操作默认会包含原邮件的所有内容(包括附件),无需额外配置参数。

内容的提问来源于stack exchange,提问作者NealWalters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 17:19:58