Outlook REST API - 发送为

问题描述 投票:0回答:1

我目前正在使用Outlook REST API发送电子邮件。从用户邮箱发送时工作正常,例如:

https://outlook.office.com/api/v2.0/users/[email protected]/sendMail

'[email protected]'是Azure AD中有效用户帐户的UPN。

我需要做的是“发送为”共享邮箱。根据文档,这可以通过更改JSON请求正文中的“From”属性来实现。一个例子是:

{
  "Message": {
    "Subject": "Email Unit Test",
    "Body": {
      "ContentType": "HTML",
      "Content": "Message body"
    },
    "ToRecipients": [
      {
        "EmailAddress": {
          "Address": "[email protected]"
        }
      }
    ],
    "Attachments": [
    ],
    "From": {
      "EmailAddress": {
        "Address": "[email protected]"
      }
    },
    "Sender": {
      "EmailAddress": {
        "Address": "[email protected]"
      }
    }
  },
  "SaveToSentItems": "false"
}

现在,当我向[email protected]发送“发送为”和“代表发送”访问共享邮箱时,这有效。收件人会收到一封电子邮件,其中包含来自“[email protected]代表[email protected]”的字段。然而,我想要的是,电子邮件只显示为在没有代表用户的情况下从shared_mailbox发送。为了进一步测试这一点,我删除了“代表发送”访问权限并仅保留了“发送为”访问权限。在API中,我现在收到一个错误:

{
    "error": {
        "code": "ErrorSendAsDenied",
        "message": "The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account., Cannot submit message."
    }
}

有趣的是,在我的Outlook客户端中,我仍然可以从共享邮箱发送电子邮件,它按预期工作,而不是在“发件人”字段中“代表”。我开始怀疑这是否是REST API的限制,但Microsoft文档中没有任何内容可以暗示这一点。

有没有人有过与REST API相似的经历?

outlook outlook-restapi
1个回答
0
投票

我尝试做同样的事情,似乎REST API允许您实现“代表发送”而不是“发送为”功能。

© www.soinside.com 2019 - 2024. All rights reserved.